简介

settings.xml文件中的settings元素包含了很多子元素,它们定义的值被用来配置Maven的执行情况。该settings文件的设置会被应用到很多个项目上,因此这里的设置不应该和任何一个特定的项目绑定,并且该设置的内容也不应该分发给它人。该文件定义的值包括本地仓库地址,候选的远程仓库仓库服务器,以及一些认证信息。settings.xml文件可位于两个地方:

• Maven安装目录: $M2_HOME/conf/settings.xml

• 用户特定的Settings文件: ~/.m2/settings.xml

这里是settings元素下最顶层元素的概览:

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种类型值:

  1. env.X,返回当前的环境变量
  2. project.x:返回pom中定义的元素值,如project.version
  3. settings.x:返回settings.xml中定义的元素
  4. java 系统属性:所有经过java.lang.System.getProperties()返回的值
  5. 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>

setting文件配置相关推荐

  1. setting文件配置(通用型)

    <?xml version="1.0" encoding="UTF-8"?><!-- Licensed to the Apache Softw ...

  2. java settings文件夹_JAVA工具例大全--Setting文件读取配置参数

    用类cn.hutool.setting.AbsSetting的如下方法:getDouble public Double getDouble(String key, String group) 获取do ...

  3. Maven中setting文件的配置

    镜像服务器的修改: <mirror><id>alimaven</id><name>aliyun maven</name><url> ...

  4. 开发技术-setting文件与pom文件配置maven私服

    1.需求: 今天公司替换私服地址,原有的地址弃用了,重新搞了下私服.记录一下. 2.实现: 1)setting文件中mirrors节点里配置镜像 <mirror><id>nex ...

  5. Django静态文件配置

    本文目的 最近用django开发项目,发现django的静态文件(js,css和img等)配置比较麻烦,开发环境和生产环境的配置还不一样,这里记录一下,作为备忘.我当前使用的版本是django v1. ...

  6. 新项目新工作空间新仓库新setting文件

    maven项目涉及到仓库,本地jar包存放在本地仓库中,新项目新工作空间新仓库新setting文件,可以避免很多问题,不同项目工程的版本可能不一样,所涉及的jar包版本可能也不一样,不分开会有一些冲突 ...

  7. nexus-3.6.0-02-unix.tar.gz安装(Centos下),maven setting.xml配置案例,项目root的pom.xml配置,parent-pom的pom.xml配置案例

    1.下载nexus 进入:http://www.sonatype.org/nexus/downloads/ 说明: [OSS = Open Source Software,开源软件 – 免费] [FR ...

  8. VUE config/index.js文件配置

     当我们需要和后台分离部署的时候,必须配置config/index.js: 用vue-cli 自动构建的目录里面  (环境变量及其基本变量的配置) 1 2 3 4 5 6 7 8 9 10 11 ...

  9. django2.0media用户上传文件配置及使用方法

    1.setting.py配置 #用户文件上传至media MEDIA_URL='/media/' MEDIA_ROOT=os.path.join(BASE_DIR,"media") ...

最新文章

  1. 16进制数组转成10进制 qt_计算机组成原理(进制数及转换)
  2. 关于System.Web.Caching的“未将对象引用设置到对象的实例”错误
  3. 广州.NET 俱乐部第三次聚会成功举办。
  4. ecshop几个价格
  5. CSRF Failed: CSRF token missing or incorrect.
  6. [Objective-c 基础 - 1.3] OC带返回值的类方法
  7. java学习(22):if语句
  8. java数字不等于_java – 仅使用set中的数字查找等于或大于给定目标的总和
  9. dumpbin的使用
  10. Oracle系统查询的语句
  11. 【大数据课程设计】出租车轨迹数据分析
  12. 沟通管理-输入、输出、工具和技术
  13. 计算机软件能删除吗,怎么彻底清除电脑软件鲁大师?卸载对系统有影响吗?
  14. c语言内存不能为written,该内存不能为written的解决方法 has written 和wrote的区别
  15. Aras Innovator: Catagoy, Itemtype, Item, Relationship的视图
  16. 微信的“QQ邮箱提醒”接收发往网易163邮件
  17. PS快速美白磨皮方法
  18. 腾讯2018秋招笔试真题-小Q的歌单
  19. 计算机组装与维护doc,新版计算机组装与维护.doc
  20. 对有序表的查找(快步搜索算法)

热门文章

  1. 你是当“鸡头”还是做“凤尾”
  2. grep中使用\d匹配数字不成功的原因
  3. Confluence 6 创建你的个人空间
  4. 程序猿的2019年终总结
  5. #osp: INITIALIZATION ERROR --> #osp:api: could not find module initializer
  6. 自然语言处理(NLP)之命名实体识别
  7. [哈夫曼树][堆]JZOJ 4210 我才不是萝莉控呢qaq
  8. 全球与中国半导体AMC过滤器市场发展方向分析及未来前景展望报告2022-2028年
  9. ubuntu安装wine和QQ微信
  10. 【操作系统-进程】PV操作——吸烟者问题