maven入門(2)settings.xml
一、簡介
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 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 >
|
二、簡單值
localRepository:這個值是構建系統的本地倉庫的路徑。默認的值是${user.home}/.m2/repository.如果一個系統想讓所有登陸的用戶都用同一個本地倉庫的話,這個值是極其有用的。
interactiveMode:如果Maven要試圖與用戶交互來得到輸入就設置為true,否則就設置為false,默認為true。
usePluginRegistry:如果Maven使用${user.home}/.m2/plugin-registry.xml來管理plugin的版本,就設置為true,默認為false。
offline:如果構建系統要在離線模式下工作,設置為true,默認為false。如果構建服務器因為網絡故障或者安全問題不能與遠程倉庫相連,那麽這個設置是非常有用的。
三、PluginGroups(插件組)
這個元素包含了一系列pluginGroup元素,每個又包含了一個groupId。當一個plugin被使用,而它的groupId沒有被提供的時候,這個列表將被搜索。這個列表自動的包含了org.apache.maven.plugins和org.codehaus.mojo。
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 >
|
四、Servers(服務器)
1. 定義jar包下載的Maven倉庫
2. 定義部署服務器
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 >
|
tomcat: 部署服務器
shiyue: Mave私服
五、Mirrors(鏡像)
指定倉庫的地址,則默認從指定的鏡像下載jar包及插件
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 >
|
六、Proxies(代理)
有時候你所在的公司基於安全因素考慮,要求你使用通過安全認證的代理訪問因特網。這時就需要為Maven配置HTTP代理。
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://maven.apache.org/settings.html
maven入門(2)settings.xml