maven 配置篇 之 settings.xml
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基本结构如下:
- <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.0
- http://maven.apache.org/xsd/settings-1.0.0.xsd">
- <localRepository/>
- <interactiveMode/>
- <usePluginRegistry/>
- <offline/>
- <pluginGroups/>
- <servers/>
- <mirrors/>
- <proxies/>
- <profiles/>
- <activeProfiles/>
- </settings>
简单介绍一下几个主要的配置因素:
localRepository:表示本地库的保存位置,也就是maven2主要的jar保存位置,默认在${user.dir}/.m2/repository,如果需要另外设置,就换成其他的路径。
offline:如果不想每次编译,都去查找远程中心库,那就设置为true。当然前提是你已经下载了必须的依赖包。
Servers
在POM中的 distributionManagement元素定义了开发库。然而,特定的username和pwd不能使用于pom.xml,所以通过此配置来保存server信息
- <servers>
- <server>
- <id>server001</id>
- <username>my_login</username>
- <password>my_password</password>
- <privateKey>${usr.home}/.ssh/id_dsa</privateKey>
- <passphrase>some_passphrase</passphrase>
- <filePermissions>664</filePermissions>
- <directoryPermissions>775</directoryPermissions>
- <configuration></configuration>
- </server>
- </servers>
- id:server 的id,用于匹配distributionManagement库id,比较重要。
- username, password:用于登陆此服务器的用户名和密码
- privateKey, passphrase:设置private key,以及passphrase
- filePermissions, directoryPermissions:当库文件或者目录创建后,需要使用权限进行访问。参照unix文件许可,如664和775
Mirrors
表示镜像库,指定库的镜像,用于增加其他库
- <mirrors>
- <mirror>
- <id>planetmirror.com</id>
- <name>PlanetMirror Australia</name>
- <url>http://downloads.planetmirror.com/pub/maven2</url>
- <mirrorOf>central</mirrorOf>
- </mirror>
- </mirrors>
- id,name:唯一的标志,用于区别镜像
- url:镜像的url
- mirrorOf:此镜像指向的服务id
Proxies
此设置,主要用于无法直接访问中心的库用户配置。
- <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>
- 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 发布。
- <repositories>
- <repository>
- <id>repo-local</id>
- <name>Internal 开发库</name>
- <url>http://192.168.0.2:8082/repo-local</url>
- <releases>
- <enabled>true</enabled>
- <updatePolicy>never</updatePolicy>
- <checksumPolicy>warn</checksumPolicy>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- <layout>default</layout>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>repo-local</id>
- <name>Internal 开发库</name>
- <url>http://192.168.0.2:8082/repo-local</url>
- <releases>
- <enabled>true</enabled>
- <updatePolicy>never</updatePolicy>
- <checksumPolicy>warn</checksumPolicy>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- <layout>default</layout>
- </pluginRepository>
- </pluginRepositories>
releases, snapshots:每个产品的版本的Release或者snapshot(注:release和snapshot的区别,release一般是比较稳定的版本,而snapshot基本上不稳定,只是作为快照)
properties
maven 的properties作为placeholder值,如ant的properties。
包括以下的5种类型值:
- env.X,返回当前的环境变量
- project.x:返回pom中定义的元素值,如project.version
- settings.x:返回settings.xml中定义的元素
- java 系统属性:所有经过java.lang.System.getProperties()返回的值
- x:用户自己设定的值
Activation
用于激活此profile
- <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>
- jdk:如果匹配指定的jdk版本,将会激活
- os:操作系统
- property:如果maven能检测到相应的属性
- file: 用于判断文件是否存在或者不存在
除了使用activation来激活profile,同样可以通过activeProfiles来激活
Active Profiles
表示激活的profile,通过profile id来指定。
- <activeProfiles>
- <activeProfile>env-test</activeProfile> 指定的profile id
- </activeProfiles>
maven 配置篇 之 settings.xml的更多相关文章
- maven 配置篇 之pom.xml
http://www.blogjava.net/zyl/archive/2006/12/30/91055.html http://maven.apache.org/pom.html的翻译. m ...
- maven 配置篇 之pom
maven 配置篇 之pom.xml(一) 博客分类: pm mavenXML配置管理项目管理junit 说完了settings.xml配置,下来说一下maven2的主要配置pom.xml ...
- Maven的仓库和settings.xml配置文件
(尊重劳动成果,转载请注明出处:https://blog.csdn.net/qq_25827845/article/details/83549846冷血之心的博客) 快速导航: Maven基础概念和安 ...
- 配置用户范围settings.xml
Maven用户可以选择配置<<MavenHome>>/conf/settings.xml或者<<UserHome>>/.m2/settings.xml. ...
- 设置阿里云maven中央仓库的settings.xml
本来想找一个可用的设置文件,结果乱七八糟的,干脆自己做了一个,同时还放上了Spring的SNAPSHOT和MILESTONE/RELEASE仓库,希望能帮到一些人. <?xml version= ...
- maven command line specified settings.xml
1. using argument parameter --settings / or -s for shot mvn install --settings c:\user\settings.xml ...
- [JAVA] maven 阿里云节点 settings.xml
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...
- Spring Tool Suite 使用自带maven速度慢---修改settings.xml更新mirror方法
(1)打开sts,windows --> preference,找到maven,并设置如下. (2)修改该文件,如下 <mirror> <id>nexus-aliyun& ...
- maven配置篇
1,windows A)安装maven之前,确认已正确安装JDK B)下载maven http://maven.apache.org/download.html C)将压缩包解压到指定目录,E:\ap ...
随机推荐
- 【放松一下】北美小游戏排行榜TOP10——“点击英雄”
大家平时工作都比較忙,在这里推荐一款游戏让大家放松一下.让你体验到指数爆炸般挣钱的快感. 北美小游戏排行榜TOP10--"点击英雄" 简要说明: 游戏能够挂机,关闭电脑.游戏也会自 ...
- String类源码解析
1. String是使用char[]数组来存储的,并且String值在创建之后就不可以改变了.char[]数组的定义为: /** The value is used for character sto ...
- iOS/MAC 数据压缩与解压缩及常用算法 LZMA、ZLIB
苹果提供的常用的数据压缩算法LZMA.ZLIB.LZ4等: 这三种算法也是苹果建议的,可跨平台使用: 定义如下: /* Commonly-available encoders */ COMPRESSI ...
- Windows中读写ini文件
.ini 文件是Initialization File的缩写,即初始化文件,是windows的系统配置文件所采用的存储格式,来配置应用软件以实现不同用户的要求.配置文件有很多种如ini配置文件,XML ...
- Linux 添加开机启动项的两种方法
1.编辑文件 /etc/rc.localvim /etc/rc.local #!/bin/sh## This script will be executed *after* all the oth ...
- java写桌面程序
一:使用java swing开发窗口程序 简述: 1.文章内容主要是使用java swing类库开发一个小的窗口程序,然后使用exe4j发布成exe可以安装的程序,让初学者对使用java来做pc软件开 ...
- [转]Redis cluster failover
今天测试了redis cluster failover 功能,在切换过程中很快,但在failover时有force 与takeover 之分 [RHZYTEST_10:REDIS:6237:M ~] ...
- 检查linux的磁盘空间占用
先初步看看哪个目录占用最大$ df -h 然后细看遍历某目录的占用情况:$ sudo du -a /data | sort -nr | less(单位是KB)
- 刨根问底 | Elasticsearch 5.X集群多节点角色配置深入详解【转】
转自:https://blog.csdn.net/laoyang360/article/details/78290484 1.问题引出 ES5.X节点类型多了ingest节点类型. 针对3个节点.5个 ...
- Win10添加右键在此处打开命令行
通过添加注册表项,实现右击“在此处打开命令行功能” 注册表位置:HKEY_CLASSES_ROOT\Directory\Background\shell\ win10系统用标识右键菜单打开命令行的键, ...