maven運(yùn)行時(shí)的配置文件settings.xml
安裝位置
- 全局配置:${maven_home}/config/settings.xml
- 用戶配置:~/.m2/settings.xml
如果全局配置與用戶配置同時(shí)存在薄疚,會進(jìn)行合并舶赔,相同配置則以用戶配置優(yōu)先辅鲸。
配置節(jié)點(diǎn)
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
localRepository
本地倉庫路徑,不配置則默認(rèn)為${user.home}/.m2/repository
interactiveMode
交互模式贷痪,是否接受用戶輸入,默認(rèn)為true
offline
是否在離線模式下運(yùn)行,默認(rèn)是false
pluginGroups
插件瑟由。通過在pluginGroup節(jié)點(diǎn)下配置id標(biāo)識济竹,在命令行中使用到的插件需要在這里配置痕檬。注:org.apache.maven.plugins 和 org.codehaus.mojo里面的差價(jià)自動包含不需要配置。如下配置:
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<pluginGroups>
<pluginGroup>org.eclipse.jetty</pluginGroup>
</pluginGroups>
...
</settings>
如上配置可以在命令行執(zhí)行如下命令:
mvn jetty:run
servers
在項(xiàng)目的POM中可以配置上傳和下載( repositories and distributionManagement )的倉庫送浊,但是倉庫對應(yīng)的用戶名梦谜、密碼、秘鑰袭景、權(quán)限等敏感信息應(yīng)當(dāng)在構(gòu)建服務(wù)器上配置唁桩,即在本節(jié)點(diǎn)之下。
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
...
</settings>
- id:服務(wù)器的id耸棒,需要與倉庫和鏡像中對應(yīng)(repository/mirror)
mirrors
鏡像倉庫地址配置荒澡,參考地址
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<mirrors>
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
...
</settings>
- id:多個(gè)竟像時(shí),id不能重復(fù)
- mirrorOf:當(dāng)前id對應(yīng)的鏡像与殃,不能與id相同
proxies
代理信息的配置
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<proxies>
<proxy>
<id>myproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
</proxy>
</proxies>
...
</settings>
- active:true表示當(dāng)前代理有效单山,false表示當(dāng)前代理無效
- nonProxyHosts:不需要通過代理的主機(jī)
profiles
這里的profile是項(xiàng)目中pom.xml中profile節(jié)點(diǎn)的縮減版,是全局配置幅疼,并不針對于單獨(dú)的項(xiàng)目米奸。這里的profile只包含四個(gè)子節(jié)點(diǎn),分別是:activation爽篷,repositories悴晰,properties,pluginRepositories
settings.xml中profile配置會覆蓋項(xiàng)目中pom.xml或者 profiles.xml中配置
activation
這里配置的是profile的關(guān)鍵信息,與pom中的profile類似铡溪,可以定義指定環(huán)境下參數(shù)使用漂辐。
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>mavenVersion</name>
<value>2.0.3</value>
</property>
<file>
<exists>${basedir}/file2.properties</exists>
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
...
</profile>
</profiles>
...
</settings>
- jdk:jdk版本配置,只是jdk版本的前綴棕硫,會在環(huán)境中尋找符合前綴條件的jdk來使用髓涯,maven2.1開始支持區(qū)間配置。參考
- os:系統(tǒng)配置饲帅。參考
- porperty:當(dāng)maven需要某些屬性的時(shí)候复凳,會從這里尋找name,value對灶泵∮耍可以與pom中配置相同的name,對應(yīng)不同的value
- file:通過給定文件赦邻,在哪個(gè)文件存在髓棋,哪個(gè)文件不存在的情況profile生效
profile的生效與否不僅可以在這里配置,同時(shí)可以在命令行通過 -P profileid使其生效
通過maven-help-plugin查看當(dāng)前構(gòu)建下有效的profile
mvn help:active-profiles
properties
maven的屬性通過占位符 ${X}來配置惶洲,在settings.xml中有5中不同格式的配置按声。
- env.X: Prefixing a variable with “env.” will return the shell’s environment variable. For example, path environment variable (%PATH% in Windows).
- project.x: A dot (.) notated path in the POM will contain the corresponding element’s value. For example: <project><version>1.0</version></project> is accessible via ${project.version}.
- settings.x: A dot (.) notated path in the settings.xml will contain the corresponding element’s value. For example: <settings><offline>false</offline></settings> is accessible via ${settings.offline}.
- Java System Properties: All properties accessible via java.lang.System.getProperties() are available as POM properties, such as ${java.home}.
- x: Set within a <properties /> element or an external files, the value may be used as ${someVar}.
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<profiles>
<profile>
...
<properties>
<user.install>${user.home}/our-project</user.install>
</properties>
...
</profile>
</profiles>
...
</settings>
repository
遠(yuǎn)程倉庫的配置
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<profiles>
<profile>
...
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
...
</pluginRepositories>
...
</profile>
</profiles>
...
</settings>
- enabled:true表示生效,false表示不生效
- updatePolicy:更新策略恬吕∏┰颍可選值:always, daily (默認(rèn))铐料,interval:X (X整數(shù)渐裂,單位:分鐘) , never
- checksumPolicy:部署到倉庫策略钠惩∑饬梗可選擇:ignore,fail篓跛, warn on missing 膝捞, incorrect checksums
- layout:maven2開始又默認(rèn)配置
pluginRepositories
插件倉庫配置,配置類似于repositories
activeProfiles
配置哪些profile是生效的愧沟,指向是profile的id蔬咬,如果配置的id不存在,不會有任何問題沐寺。配置在settings.xml林艘、pom.xml、和profile.xml中的profile都可以在這里指定芽丹。
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<activeProfiles>
<activeProfile>env-test</activeProfile>
</activeProfiles>
</settings>
其他文章列表
spring web service系列1
spring web service系列2
spring web service系列3
Nginx轉(zhuǎn)發(fā)請求過程解析
Nginx中的負(fù)載均衡算法
Nginx upstream指令配置說明
Nginx中虛擬服務(wù)器server指令配置說明
Nginx中proxy_pass/proxy_redirect/proxy_set_header配置說明
Nginx中ngx_http_core_module相關(guān)指令配置說明
Java自帶JVM監(jiān)控工具jstat使用詳細(xì)說明
Java自帶JVM監(jiān)控工具jps使用詳細(xì)說明
Java自帶故障分析工具jmap工具使用說明
Java自帶故障分析工具jhat工具使用說明