maven2 setting文件详解
来源:互联网 发布:建材行业不适合做seo 编辑:程序博客网 时间:2024/05/21 05:17
以下完全照搬官网:http://maven.apache.org/settings.html 只是加上一点自己的理解而已
可以具有两个setting文件:
1.$M2_HOME/conf/settring.xml安装Maven就有的系统setting(各个用户有效的全局的)
2.${user.home}/.m2/settring.xml用户自己加在Repository里的setting文件(用户级的)
元素总览:
<settings xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/settings-1.0.0.xsd"><localRepository/><interactiveMode/><usePluginRegistry/><offline/><pluginGroups/><servers/><mirrors/><proxies/><profiles/><activeProfiles/></settings>
<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>
这些是在这里定义的。
id:与distributionManagement中的repository中的元素id对应,用于表示一个server
username,password:如果server需要验证的话,这一对元素就是用于验证的
privateKey, passphrase:也是用于服务器验证的,前者指定私钥privateKey(默认${user.home}/.ssh/id_dsa),后者指定口号passphrase
filePermissions, directoryPermissions:使用linux中的三位数字形式标示文件与路径的权限,例如664,775等。
注意:如果使用私钥登录服务器的话,那么password就省略,否则,私钥会被忽略。
configuration:官网也没有解释。
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
id,name:server镜像的唯一标识与可读性强的名称(id才是唯一的)
mirrorOf:指定这个镜像代表的server的id,那么以后工程引用这个server的时候将不会使用server而是变成使用mirror的地址
In 2.0.9+, an enhanced syntax is supported:
- * matches all repo ids.
- external:* matches all repos except those using localhost or file based repositories. This is used in conjunction with a repository manager when you want to exclude redirecting repositories that are defined for Integration Testing.
- multiple repos may be specified using , as the delimiter
- ! may be used in conjunction with one of the above wildcards to exclude a repo id.
The order is not important from left to right as the wildcards defer to further processing and explicit includes or excludes stop the processing. Additionally, the mirror list will now be ordered using a LinkedHashMap instead of HashMap such that the user may influence match order by changing the order of the definitions in the settings.xml
Examples:
- * = everything
- external:* = everything not on the localhost and not file based.
- repo,repo1 = repo or repo1
- *,!repo1 = everything except repo1
<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>
id:表示不同的proxy
active:当有多个proxy的时候,只有active为true的时候才是有效的
protocol,host,port:协议,主机,端口
username,password:如果需要的话就加上
nonProxyHosts:排除不用代理的站点,使用“|”或者“,”符号分开不同站点,可以使用通配符“*”
activation, repositories, pluginRepositories and properties elements
activation指定激活这个profile的条件。其他激活的方法:(1)setting.xml可以通过activeProfile元素指定profile的id,来明确地激活这个profile。(2)在命令行上加上-P profile的id,也可以激活这个profile,其中可以通过“,”分开几个profile的id来指定多个。
repositories包含的repository指定依赖,它之前的activation如果符合激活条件的话就开启这个依赖
pluginRepositories和properties也一样,如果activation符合激活条件,则它们将被激活
例子1:如果使用jdk-1.4的话,jdk的依赖将会被激活
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<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>
例子2:如果target-env的属性值为dev的时候,就激活tomcatPath的属性,其他地方肯定会有元素引用这个属性,例如后面引用
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>
引用tomcatPath
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
属性的引用可以通过${},其中:
1)env.***是引用命令行comandline参数既环境变量等参数的值,例如%{env.PATH}引用环境变量path的值
2)project.***引用pom文件中project的元素值,例如pom中有个<project><version>1.0</version></project>,那么可以%{project.version}
3)setting.***引用setting文件中的元素值,例如:<settings><offline>false</offline></settings> is accessible via ${settings.offline}
4)java.***,java System Properties:在java语言中可以通过java.lang.System.getProperties() 获得的值都可以通过此来获得,例如:${java.home}
5)***是在<properties/>中定义了的可以直接引用的属性,方法%{someVar}。
<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>
1)releases, snapshots:(理解不了,原文照搬)These are the policies for each type of artifact, Release or snapshot. With these two sets, a POM has the power to alter the policies for each type independent of the other within a single repository. For example, one may decide to enable only snapshot downloads, possibly for development purposes.
2)enabled:true或者false来指明这个repository哪个类型被开启
3)updatePolicy:升级策略。The choices are: always, daily (default), interval:X (where X is an integer in minutes) or never
4)checksumPolicy:When Maven deploys files to the repository, it also deploys corresponding checksum files. options are to ignore, fail, or warn on missing or incorrect checksums
5)layout:In the above description of repositories, it was mentioned that they all follow a common layout. This is mostly correct. Maven 2 has a default layout for its repositories; however, Maven 1.x had a different layout. Use this element to specify which if it is default or legacy.
结构如同Repositories,但是可以这样理解,repositories用于工程运行之前的,plugin Repositories用于运行。例如tomcat jetty等都是plugins,而jdk,jar等运行之前的工程编译时候就已经用到了
- maven2 setting文件详解
- maven2 setting文件详解
- maven2 Setting文件
- maven2 setting
- Maven2 setting.xml
- maven的setting文件详解
- maven配置setting.xml文件详解
- Maven之setting.xml文件标签详解
- maven的setting.xml文件配置详解
- maven的setting.xml文件配置详解
- maven里的setting文件详解
- maven的setting.xml文件配置详解
- maven的setting.xml文件配置详解
- maven配置setting.xml文件详解
- maven的setting.xml文件的详解
- Maven配置之Setting文件详解
- maven的setting.xml文件配置详解
- Maven2插件开发详解
- js屏蔽浏览器(IE和FireFox)的刷新和右键等功能
- C#:反射以及Attribute在ORM中的应用
- 想像五年之后的你
- 测试提问单
- Unix/Linux常用监控和管理命令工具
- maven2 setting文件详解
- 关于位结构体
- hibernate使用from (select ……)子查询的方法
- 如何用正确的方法来写出质量好的软件的75条体会
- maven 配置篇 之pom.xml
- suse linux 硬盘安装心得
- c++强制类型转换小结
- 。。。。。。。
- 程序员的九重境界