maven(六)maven配置文件

来源:互联网 发布:出入境旅游数据统计 编辑:程序博客网 时间:2024/05/23 21:58

如果在Eclipse中使用过Maven插件,想必会有这个经验:配置settings.xml文件的路径。 settings.xml文件是干什么的,为什么要配置它呢? 从settings.xml的文件名就可以看出,它是用来设置maven参数的配置文件。并且,settings.xml是maven的全局配置文件。而pom.xml文件是所在项目的局部配置。 Settings.xml中包含类似本地仓储位置、修改远程仓储服务器、认证信息等配置。

settings.xml文件一般存在于两个位置: 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: ({user.home}/.m2/settings.xml note:用户配置优先于全局配置。)

需要注意的是:局部配置优先于全局配置。 配置优先级从高到低:pom.xml> user settings > global settings 如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。

<?xml version="1.0" encoding="UTF-8"?><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   修改本地仓库所在位置,默认在/我的文档/.m2/repository文件夹下。如果我把下列注释打开,默认仓库建在:E:\test-maven\repo    <localRepository>E:\test-maven\repo</localRepository>  -->  <!-- interactiveMode   maven是否需要和用户交互以获得输入。 如果maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。  <interactiveMode>true</interactiveMode>  -->  <!-- offline  maven是否需要在离线模式下运行。 如果构建系统需要在离线模式下运行,则为true,默认为false。 当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。  <offline>false</offline>  -->  <!-- pluginGroups 当插件的组织id(groupId)没有显式提供时,供搜寻插件组织Id(groupId)的列表。 该元素包含一个pluginGroup元素列表,每个子元素包含了一个组织Id(groupId)。 当我们使用某个插件,并且没有在命令行为其提供组织Id(groupId)的时候,Maven就会使用该列表。默认情况下该列表包含了org.apache.maven.plugins和org.codehaus.mojo。   -->  <pluginGroups>    <!-- pluginGroup    <pluginGroup>org.codehaus.mojo</pluginGroup>     -->  </pluginGroups>  <!-- proxies  为仓库列表配置的下载镜像列表。   -->  <proxies>    <!-- proxy     此设置,主要用于无法直接访问中心的库用户配置。     id:代理的标志     active:是否激活代理     protocol, host, port:protocol://host:port 代理     username, password:用户名和密码     nonProxyHosts: 不需要代理的host    <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>  <!-- servers   在POM中的 distributionManagement元素定义了开发库。然而,特定的username和pwd不能使用于pom.xml,所以通过此配置来保存server信息   |-->  <servers>    <!-- server    id:server 的id,用于匹配distributionManagement库id,比较重要。    username, password:用于登陆此服务器的用户名和密码    privateKey, passphrase:设置private key,以及passphrase    filePermissions, directoryPermissions:当库文件或者目录创建后,需要使用权限进行访问。    <server>      <id>deploymentRepo</id>      <username>repouser</username>      <password>repopwd</password>    </server>    -->    <!-- Another sample, using keys to authenticate.    <server>      <id>siteServer</id>      <privateKey>/path/to/private/key</privateKey>      <passphrase>optional; leave empty if not used.</passphrase>    </server>    -->  </servers>  <!-- mirrors   表示镜像库,指定库的镜像,用于增加其他库   -->  <mirrors>    <!-- mirror    id,name:唯一的标志,用于区别镜像    url:镜像的url    mirrorOf:此镜像指向的服务id    <mirror>      <id>mirrorId</id>      <mirrorOf>repositoryId</mirrorOf>      <name>Human Readable Name for this Mirror.</name>      <url>http://my.repository.com/repo/path</url>    </mirror>     -->  </mirrors>  <!-- profiles   类似于pom.xml中的profile元素,主要包括activation,repositories,pluginRepositories 和properties元素  刚开始接触的时候,可能会比较迷惑,其实这是maven2中比较强大的功能。从字面上来说,就是个性配置。  单独定义profile后,并不会生效,需要通过满足条件来激活。  <profiles>    <!-- profile    <profile>      <id>jdk-1.4</id>      <activation>        <jdk>1.4</jdk>      </activation>repositories 和pluginRepositories  定义其他开发库和插件开发库。对于团队来说,肯定有自己的开发库。可以通过此配置来定义。      <repositories>        <repository>          <id>jdk14</id>          <name>Repository for JDK 1.4 builds</name>          <url>http://www.myhost.com/maven/jdk14</url>          <layout>default</layout>          <snapshotPolicy>always</snapshotPolicy>        </repository>      </repositories>    </profile>    <profile>      <id>env-dev</id>      <activation>          profile默认是否激活的标识列表        <property>          <name>target-env</name>          <value>dev</value>        </property>      </activation>      <properties>        <tomcatPath>/path/to/tomcat/instance</tomcatPath>      </properties>    </profile>    -->  </profiles>  <!-- activeProfiles   手动激活profiles的列表,按照profile被应用的顺序定义activeProfile。 该元素包含了一组activeProfile元素,每个activeProfile都含有一个profile id。任何在activeProfile中定义的profile id,不论环境设置如何,其对应的 profile都会被激活。如果没有匹配的profile,则什么都不会发生。 例如,env-test是一个activeProfile,则在pom.xml(或者profile.xml)中对应id的profile会被激活。如果运行过程中找不到这样一个profile,Maven则会像往常一样运行。  <activeProfiles>    <activeProfile>alwaysActiveProfile</activeProfile>    <activeProfile>anotherAlwaysActiveProfile</activeProfile>  </activeProfiles>  --></settings>
原创粉丝点击