maven环境搭建:

    1.官网下载zip包,解压至任意目录(如:E:\wly\apache-maven-3.2.5)
    2.环境变量MAVEN_HOME(E:\wly\apache-maven-3.2.5)、path追加"%MAVEN_HOME%\bin;"
    3.cmd命令行mvn -v,正常输出maven版本代表OK

  settings.xml详解:

  操作setting.xml之前,先了解一下maven是基于用户的。默认全局的配置文件"maven安装目录/conf/settings.xml",可以拷贝"settings.xml"放到"用户目录/.m2"/下,此时用户目录下的settings.xml会覆盖原配置。

  接下来我们看一下settings.xml中都能配置什么?下面内容以3.3.9版本为例:

  官方文档传送门:http://maven.apache.org/ref/3.3.9/maven-settings/settings.html

配置大纲:

localRepository     本地仓库,默认在用户/.m2/repository

interactiveMode     交互模式,默认为true
usePluginRegistry   是否使用plugin-registry.xml文件管理插件版本,默认为false offline        是否使用离线模式,默认为false proxies/proxy*    配置代理,通常给无法直接访问中央仓库的用户使用 servers/server*   服务器身份认证,比如当需要deploy一个包到远程仓库时,需要权限验证。此配置属于公用配置,且配置在pom.xml中不太安全,通常与<distributionManagement><id>匹配 mirrors/mirror*   镜像配置,会覆盖远程仓库配置 profiles/profile* 用于配置不同环境的差异文件 activeProfiles/activeProfile* 手动激活的默认差异文件 pluginGroups/pluginGroup* 当插件的groupId没有显式提供,从此插件的group中寻找需要的插件

详细配置说明:

代理(proxies/proxy*):

<proxies>
<proxy>
<!-- 代理标识 -->
<id>testProxy</id>
<!-- 是否激活,默认是true -->
<active>true</active>
<!-- 代理协议 -->
<protocol>http</protocol>
<!-- 用户名 -->
<username>wang</username>
<!-- 密码 -->
<password>123</password>
<!-- 端口 -->
<port>8099</port>
<!-- 主机 -->
<host>proxy.xxx.com</host>
<!-- 不需要代理的主机 -->
<nonProxyHosts>*.xx1.com|*.xx2.com</nonProxyHosts>
</proxy>
</proxies>

服务器认证(servers/server*):支持用户名/密码,公钥/私钥两种认证方式

<servers>
<server>
<!-- 服务标识 -->
<id>server1</id>
<!-- 用户名 -->
<username>wang</username>
<!-- 密码 -->
<password>123</password>
</server>
<server>
<id>server2</id>
<privateKey>wang</username>
<passphrase>456</passphrase>
</server>
</servers>

镜像(mirrors/mirror*):用<mirrorOf>配置覆盖一个或者多个仓库的配置。

<mirrorOf>元素:

  * = everything

  external:* = everything not on the localhost and not file based.

  repo,repo1 = repo or repo1

  *,!repo1 = everything except repo1

优点:1.速度快 2.使用自定义镜像可管控

<mirrors>
<mirror>
<!-- 镜像id,唯一标识 -->
<id>central-mirror</id>
<!-- 镜像名称 -->
<name>Maven China Mirror</name>
<!-- 镜像地址 -->
<url>http://search.maven.org/#browse</url>
<!-- 这个是谁的镜像,覆盖哪个仓库的配置 -->
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

环境差异文件(profiles/profile*):

<profiles>
<!--通过某些条件匹配来激活不同<profile>,如jdk、os、属性和属性值等等-->
<profile>
<!-- 唯一标识id -->
<id>jdk-1.6</id>
<!-- 激活条件 -->
<activation>
<jdk>1.6</jdk>
</activation>
<!-- 键值对属性 -->
<properties>
<property.key>property.value</property.key>
         <!--
            maven支持使用占位符的方式设置或获取值
            1.env:操作系统环境变量
            2.project.x:当前project的属性
            3.setttings.x:对应settings.xml文件的属性
            4.properties文件中的属性(redis.ip=10.11.12.13):redis.ip
            5.x:<properties>中设置的属性
          -->
                <anykey>${env.path}</anykey>
</properties>
            <!-- 仓库配置 -->
<repositories>
<repository>
<id>仓库id</id>
<name>仓库名称</name>
<url>仓库url</url>
<layout>在Maven 2/3中都是default,只有在Maven 1.x中才是legacy,默认也是default</layout>
<!-- 发布的稳定版本 -->
<releases>
<checksumPolicy>当组件校验失败时,warn或fail</checksumPolicy>
<enabled>是否使用此库下载组件</enabled>
<updatePolicy>当组件在本地不存在时的更新策略:always、daily(default)、interval:xx(in minutes)、never</updatePolicy>
</releases>
<!-- 快照版本,注释同上 -->
<snapshots>
<checksumPolicy></checksumPolicy>
<enabled></enabled>
<updatePolicy></updatePolicy>
</snapshots>
</repository>
</repositories>
<!-- 插件仓库 -->
<pluginRepositories>
<pluginRepository>
<!-- 配置与repository类似 -->
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

激活某个差异文件(activeProfiles/activeProfile*):

<!-- 指定某个profile生效 -->
<activeProfiles>
<activeProfile>对应profile id</activeProfile>
</activeProfiles>

当插件groupId没有显示提供,使用此groupId进行查找(pluginGroups/pluginGroup*):

<pluginGroups>
<!-- 当插件groupId没有显示提供,使用此groupId查找插件 -->
<!-- 官网:(Many) List of groupIds to search for a plugin when that plugin groupId is not explicitly provided. -->
<pluginGroup>org.mortbay.jetty</pluginGroup>
<pluginGroup>org.codehaus.cargo</pluginGroup>
</pluginGroups>

maven学习(一)setting.xml配置文件详解的更多相关文章

  1. 【maven学习】pom.xml文件详解

    环境 apache-maven-3.6.1 jdk 1.8 eclipse 4.7 POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示, ...

  2. Maven之(六)setting.xml配置文件详解

    setting.xml配置文件 maven的配置文件settings.xml存在于两个地方: 1.安装的地方:${M2_HOME}/conf/settings.xml 2.用户的目录:${user.h ...

  3. Maven之setting.xml配置文件详解

    setting.xml配置文件 maven的配置文件settings.xml存在于两个地方: 1.安装的地方:${M2_HOME}/conf/settings.xml 2.用户的目录:${user.h ...

  4. 【maven学习】settings.xml文件详解

    环境 apache-maven-3.6.1 jdk 1.8 eclipse 4.7 Settings.xml是设置maven参数的配置文件,包含类似本地仓储位置.修改远程仓储服务器.认证信息等配置.p ...

  5. Maven系列二setting.xml 配置详解

    文件存放位置 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: ${user.home}/.m2/settings.xml note:用户配置优先于全局配置.${use ...

  6. Maven中的pom.xml配置文件详解

    原文:http://blog.csdn.net/u012152619/article/details/51485297 <project xmlns="http://maven.apa ...

  7. 6.Maven之(六)setting.xml配置文件详解

    转自:https://blog.csdn.net/u012152619/article/details/51485152

  8. Java数据持久层框架 MyBatis之API学习四(xml配置文件详解)

    摘录网址: http://blog.csdn.net/u010107350/article/details/51292500 对于MyBatis的学习而言,最好去MyBatis的官方文档:http:/ ...

  9. struts2学习笔记--struts.xml配置文件详解

    这一节主要讲解struts2里面的struts.xml的常用标签及作用: 解决乱码问题 <constant name="struts.i18n.encoding" value ...

随机推荐

  1. svn 命令

    svn基本的操作流程就是: 你刚刚进入一个新的公司,让你接手一个正在进行的项目,你打开终端写下了:svn co svn://192.168.1.1/pro/domain 然后就可以在当前目录里面找到一 ...

  2. anaconda多环境配置

    分享几篇比较好的帖子: https://zhuanlan.zhihu.com/p/25198543 http://www.imooc.com/article/18123

  3. POJ 2182 Lost Cows (求序列第k大)

    题解 二分+树状数组 显然最和一个数的值就是rank 那么其它数有什么规律? 从后往前匹配rank,我们可以发现第i个数的rank为还没有匹配的rank第(a[i]+1)大的数 这可以用 树状数组+二 ...

  4. poj 1220 NUMBER BASE CONVERSION

    NUMBER BASE CONVERSION Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5976   Accepted: ...

  5. WPF Hidden和Collapsed

    对于这两种设定,其实已经提示的很清楚了 Visibility="Hidden"不显示元素,但是在布局为元素保留空间 Visibility="Collapsed" ...

  6. jQuery随笔-自定义属性获取+tooltip

    1.Jquery自定义属性获取 1) 通过自定义属性值获取document console.log($('[data-id='+item_id+']',listWrap)); $('[data-id= ...

  7. PIE SDK图像裁剪

    1.算法功能简介 图像裁剪的目的是获取选定的影像范围区域.图像裁切工具提供像素范围裁切.矢量裁切.栅格图像裁切和几何图元裁切四种方式. 像素范围裁切是基于像素坐标获取矩形裁切区域的裁切方式:矢量裁切是 ...

  8. superobject 设定排序方式

    (* * Super Object Toolkit * * Usage allowed under the restrictions of the Lesser GNU General Public ...

  9. java中的集合:继承关系和简介

    1.继承关系图 2.Collection接口 Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements).一些Collect ...

  10. 网络编程api bind函数细节 select 细节

    struct sockaddr_in bindaddr; bindaddr.sin_family = AF_INET; bindaddr.sin_addr.s_addr = htonl(INADDR_ ...