maven2 比起maven1 来说,需要配置的文件少多了,主要集中在pom.xml和settings.xml中。
    先来说说settings.xml,settings.xml对于maven来说相当于全局性的配置,用于所有的项目。在maven2中存在两个 settings.xml,一个位于maven2的安装目录conf下面,作为全局性配置。对于团队设置,保持一致的定义是关键,所以 maven2/conf下面的settings.xml就作为团队共同的配置文件。保证所有的团队成员都拥有相同的配置。当然对于每个成员,都需要特殊的 自定义设置,如用户信息,所以另外一个settings.xml就作为本地配置。默认的位置为:${user.dir} /.m2/settings.xml目录中(${user.dir} 指windows 中的用户目录)。
    settings.xml基本结构如下:

xml 代码
  1. <settings xmlns="http://maven.apache.org/POM/4.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.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>

简单介绍一下几个主要的配置因素:
localRepository:表示本地库的保存位置,也就是maven2主要的jar保存位置,默认在${user.dir}/.m2/repository,如果需要另外设置,就换成其他的路径。
offline:如果不想每次编译,都去查找远程中心库,那就设置为true。当然前提是你已经下载了必须的依赖包。
Servers
   在POM中的 distributionManagement元素定义了开发库。然而,特定的username和pwd不能使用于pom.xml,所以通过此配置来保存server信息

xml 代码
  1. <servers>
  2. <server>
  3. <id>server001</id>
  4. <username>my_login</username>
  5. <password>my_password</password>
  6. <privateKey>${usr.home}/.ssh/id_dsa</privateKey>
  7. <passphrase>some_passphrase</passphrase>
  8. <filePermissions>664</filePermissions>
  9. <directoryPermissions>775</directoryPermissions>
  10. <configuration></configuration>
  11. </server>
  12. </servers>
  • id:server 的id,用于匹配distributionManagement库id,比较重要。
  • username, password:用于登陆此服务器的用户名和密码
  • privateKey, passphrase:设置private key,以及passphrase
  • filePermissions, directoryPermissions:当库文件或者目录创建后,需要使用权限进行访问。参照unix文件许可,如664和775

Mirrors 
表示镜像库,指定库的镜像,用于增加其他库

xml 代码
  1. <mirrors>
  2. <mirror>
  3. <id>planetmirror.com</id>
  4. <name>PlanetMirror Australia</name>
  5. <url>http://downloads.planetmirror.com/pub/maven2</url>
  6. <mirrorOf>central</mirrorOf>
  7. </mirror>
  8. </mirrors>
  • id,name:唯一的标志,用于区别镜像
  • url:镜像的url
  • mirrorOf:此镜像指向的服务id

Proxies 
此设置,主要用于无法直接访问中心的库用户配置。

xml 代码
  1. <proxies>
  2. <proxy>
  3. <id>myproxy</id>
  4. <active>true</active>
  5. <protocol>http</protocol>
  6. <host>proxy.somewhere.com</host>
  7. <port>8080</port>
  8. <username>proxyuser</username>
  9. <password>somepassword</password>
  10. <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
  11. </proxy>
  12. </proxies>
  • id:代理的标志
  • active:是否激活代理
  • protocol, host, port:protocol://host:port 代理
  • username, password:用户名和密码
  • nonProxyHosts: 不需要代理的host

Profiles 
  类似于pom.xml中的profile元素,主要包括activation,repositories,pluginRepositories 和properties元素
  刚开始接触的时候,可能会比较迷惑,其实这是maven2中比较强大的功能。从字面上来说,就是个性配置。
  单独定义profile后,并不会生效,需要通过满足条件来激活。
 repositories 和pluginRepositories 
 定义其他开发库和插件开发库。对于团队来说,肯定有自己的开发库。可以通过此配置来定义。
 如下的配置,定义了本地开发库,用于release 发布。

xml 代码
  1. <repositories>
  2. <repository>
  3. <id>repo-local</id>
  4. <name>Internal 开发库</name>
  5. <url>http://192.168.0.2:8082/repo-local</url>
  6. <releases>
  7. <enabled>true</enabled>
  8. <updatePolicy>never</updatePolicy>
  9. <checksumPolicy>warn</checksumPolicy>
  10. </releases>
  11. <snapshots>
  12. <enabled>false</enabled>
  13. </snapshots>
  14. <layout>default</layout>
  15. </repository>
  16. </repositories>
  17. <pluginRepositories>
  18. <pluginRepository>
  19. <id>repo-local</id>
  20. <name>Internal 开发库</name>
  21. <url>http://192.168.0.2:8082/repo-local</url>
  22. <releases>
  23. <enabled>true</enabled>
  24. <updatePolicy>never</updatePolicy>
  25. <checksumPolicy>warn</checksumPolicy>
  26. </releases>
  27. <snapshots>
  28. <enabled>false</enabled>
  29. </snapshots>
  30. <layout>default</layout>
  31. </pluginRepository>
  32. </pluginRepositories>

releases, snapshots:每个产品的版本的Release或者snapshot(注:release和snapshot的区别,release一般是比较稳定的版本,而snapshot基本上不稳定,只是作为快照)

properties
  maven 的properties作为placeholder值,如ant的properties。
包括以下的5种类型值:

  1. env.X,返回当前的环境变量
  2. project.x:返回pom中定义的元素值,如project.version
  3. settings.x:返回settings.xml中定义的元素
  4. java 系统属性:所有经过java.lang.System.getProperties()返回的值
  5. x:用户自己设定的值

Activation 
  用于激活此profile

xml 代码
  1. <activation>
  2. <activeByDefault>false</activeByDefault>
  3. <jdk>1.5</jdk>
  4. <os>
  5. <name>Windows XP</name>
  6. <family>Windows</family>
  7. <arch>x86</arch>
  8. <version>5.1.2600</version>
  9. </os>
  10. <property>
  11. <name>mavenVersion</name>
  12. <value>2.0.3</value>
  13. </property>
  14. <file>
  15. <exists>${basedir}/file2.properties</exists>
  16. <missing>${basedir}/file1.properties</missing>
  17. </file>
  18. </activation>
  • jdk:如果匹配指定的jdk版本,将会激活
  • os:操作系统
  • property:如果maven能检测到相应的属性
  • file: 用于判断文件是否存在或者不存在

除了使用activation来激活profile,同样可以通过activeProfiles来激活
Active Profiles
表示激活的profile,通过profile id来指定。

xml 代码
    1. <activeProfiles>
    2. <activeProfile>env-test</activeProfile> 指定的profile id
    3. </activeProfiles>

maven 配置篇 之 settings.xml的更多相关文章

  1. maven 配置篇 之pom.xml

    http://www.blogjava.net/zyl/archive/2006/12/30/91055.html http://maven.apache.org/pom.html的翻译.     m ...

  2. maven 配置篇 之pom

    maven 配置篇 之pom.xml(一) 博客分类:  pm mavenXML配置管理项目管理junit      说完了settings.xml配置,下来说一下maven2的主要配置pom.xml ...

  3. Maven的仓库和settings.xml配置文件

    (尊重劳动成果,转载请注明出处:https://blog.csdn.net/qq_25827845/article/details/83549846冷血之心的博客) 快速导航: Maven基础概念和安 ...

  4. 配置用户范围settings.xml

    Maven用户可以选择配置<<MavenHome>>/conf/settings.xml或者<<UserHome>>/.m2/settings.xml. ...

  5. 设置阿里云maven中央仓库的settings.xml

    本来想找一个可用的设置文件,结果乱七八糟的,干脆自己做了一个,同时还放上了Spring的SNAPSHOT和MILESTONE/RELEASE仓库,希望能帮到一些人. <?xml version= ...

  6. maven command line specified settings.xml

    1. using argument parameter --settings  / or -s for shot mvn install --settings c:\user\settings.xml ...

  7. [JAVA] maven 阿里云节点 settings.xml

    <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...

  8. Spring Tool Suite 使用自带maven速度慢---修改settings.xml更新mirror方法

    (1)打开sts,windows --> preference,找到maven,并设置如下. (2)修改该文件,如下 <mirror> <id>nexus-aliyun& ...

  9. maven配置篇

    1,windows A)安装maven之前,确认已正确安装JDK B)下载maven http://maven.apache.org/download.html C)将压缩包解压到指定目录,E:\ap ...

随机推荐

  1. Spark2.2出现异常:ERROR SparkUI: Failed to bind SparkUI

    详细错误信息如下: // :: INFO util.log: Logging initialized @5402ms // :: INFO server.Server: jetty-9.3.z-SNA ...

  2. 【问题与解决】怎么删除TFS云端上的项目

    最近使用了Visual Stuidio提供的网络项目管理,感觉跟visual stuido结合起来还是很好用的,新建项目很简单,但是在删除项目的时候就没有那么简单了,直接通过VS的团队管理删除还会报错 ...

  3. mysql忘记密码时如何修改密码

    1.首先关闭mysql服务 2.进入mysql安装目录,我的是在C:\Program Files\MySQL\MySQL Server 5.5\bin 3.dos命令行执行:mysqld -nt -- ...

  4. 为什么虚拟 dom 会提高性能?

    虚拟 dom 相当于在 js 和真实 dom 中间加了一个缓存,利用 dom diff 算法避免了没有必要的 dom 操作,从而提高性能.用 JavaScript 对象结构表示 DOM 树的结构:然后 ...

  5. PHP 实现自动加载

    自动载入主要是省去了一个个类去 include 的繁琐,在 new 时动态的去检查并 include 相应的 class 文件. 先上代码: //index.php <?php class Cl ...

  6. 关于java多线程中异常捕获的理解

    在java多线程程序中,所有线程都不允许抛出未捕获的checked exception(比如sleep时的InterruptedException),也就是说各个线程需要自己把自己的checked e ...

  7. hive hbase区别

    1.hive是sql语言,通过数据库的方式来操作hdfs文件系统,为了简化编程,底层计算方式为mapreduce. 2.hive是面向行存储的数据库. 3.Hive本身不存储和计算数据,它完全依赖于H ...

  8. 【Shiro】小读Shiro Filter

    类继承结构图 看不明白此图不要紧,后面慢慢提到此图的类: AbstractFilter,抽象过滤器 它实现Filter.继承ServletContextSupport. 它主要实现了init(Filt ...

  9. ios调试-查看日志

    连上mac,然后打开“console.app”, 左侧设备里选这个设备.

  10. [Linux 性能调优] 网卡中断与CPU的绑定问题

    在Linux的网络调优方面,如果你发现网络流量上不去,那么有一个方面需要去查一下:网卡处理网络请求的中断是否被绑定到单个CPU(或者说跟处理其它中断的是同一个CPU). 先说一下背景 网卡与操作系统的 ...