一、简介
settings.xml对于maven来说相当于全局性的配置,用于所有的项目,当Maven运行过程中的各种配置,例如pom.xml,不想绑定到一个固定的project或者要分配给用户时,我们使用settings.xml中的settings元素来确定这些配置。这包含了本地仓库位置,远程仓库服务器以及认证信息等。
settings.xml存在于两个地方:
1.安装的地方:$M2_HOME/conf/settings.xml
2.用户的目录:${user.home}/.m2/settings.xml
前者又被叫做全局配置,后者被称为用户配置。如果两者都存在,它们的内容将被合并,并且用户范围的配置优先。
平时配置时优先选择用户目录的settings.xml
下面是settings下的顶层元素的一个概览:
1 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 4 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 5 <localRepository/> 6 <interactiveMode/> 7 <usePluginRegistry/> 8 <offline/> 9 <pluginGroups/> 10 <servers/> 11 <mirrors/> 12 <proxies/> 13 <profiles/> 14 <activeProfiles/> 15 </settings>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <pluginGroups> <pluginGroup>org.mortbay.jetty</pluginGroup> </pluginGroups> ... </settings>
<servers>
<server>
<id>tomcat</id>
<username>bruce</username>
<password>password</password>
</server>
<server>
<id>shiyue</id>
<username>admin</username>
<password>password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>mirrorId</id>
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://host:port/nexus-2.1.2/content/groups/public</url>
</mirror>
</mirrors>
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository/> <interactiveMode/> <usePluginRegistry/> <offline/> <pluginGroups/> <servers/> <mirrors/> <proxies/> <profiles/> <activeProfiles/></settings> |
|
1
2
3
4
5
6
7
8
9
10
|
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <pluginGroups> <pluginGroup>org.mortbay.jetty</pluginGroup> </pluginGroups> ...</settings> |
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<servers> <server> <id>tomcat</id> <username>bruce</username> <password>password</password> </server> <server> <id>shiyue</id> <username>admin</username> <password>password</password> </server> </servers> |
|
1
2
3
4
5
6
7
8
9
|
<mirrors> <mirror> <id>mirrorId</id> <mirrorOf>*</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://host:port/nexus-2.1.2/content/groups/public</url> </mirror> </mirrors> |
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<proxies> <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password> <host>proxy.host.net</host> <port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies> |
原文:http://www.cnblogs.com/wqsbk/p/5153031.html