maven环境搭建:

    1.官网下载zip包,解压至任意目录(如:E:\wly\apache-maven-3.2.5)
    2.环境变量MAVEN_HOME(E:\wly\apache-maven-3.2.5)、path追加"%MAVEN_HOME%\bin;"
    3.cmd命令行mvn -v,正常输出maven版本代表OK

  settings.xml详解:

  操作setting.xml之前,先了解一下maven是基于用户的。默认全局的配置文件"maven安装目录/conf/settings.xml",可以拷贝"settings.xml"放到"用户目录/.m2"/下,此时用户目录下的settings.xml会覆盖原配置。

  接下来我们看一下settings.xml中都能配置什么?下面内容以3.3.9版本为例:

  官方文档传送门:http://maven.apache.org/ref/3.3.9/maven-settings/settings.html

配置大纲:

localRepository     本地仓库,默认在用户/.m2/repository

interactiveMode     交互模式,默认为true
usePluginRegistry   是否使用plugin-registry.xml文件管理插件版本,默认为false offline        是否使用离线模式,默认为false proxies/proxy*    配置代理,通常给无法直接访问中央仓库的用户使用 servers/server*   服务器身份认证,比如当需要deploy一个包到远程仓库时,需要权限验证。此配置属于公用配置,且配置在pom.xml中不太安全,通常与<distributionManagement><id>匹配 mirrors/mirror*   镜像配置,会覆盖远程仓库配置 profiles/profile* 用于配置不同环境的差异文件 activeProfiles/activeProfile* 手动激活的默认差异文件 pluginGroups/pluginGroup* 当插件的groupId没有显式提供,从此插件的group中寻找需要的插件

详细配置说明:

代理(proxies/proxy*):

<proxies>
<proxy>
<!-- 代理标识 -->
<id>testProxy</id>
<!-- 是否激活,默认是true -->
<active>true</active>
<!-- 代理协议 -->
<protocol>http</protocol>
<!-- 用户名 -->
<username>wang</username>
<!-- 密码 -->
<password>123</password>
<!-- 端口 -->
<port>8099</port>
<!-- 主机 -->
<host>proxy.xxx.com</host>
<!-- 不需要代理的主机 -->
<nonProxyHosts>*.xx1.com|*.xx2.com</nonProxyHosts>
</proxy>
</proxies>

服务器认证(servers/server*):支持用户名/密码,公钥/私钥两种认证方式

<servers>
<server>
<!-- 服务标识 -->
<id>server1</id>
<!-- 用户名 -->
<username>wang</username>
<!-- 密码 -->
<password>123</password>
</server>
<server>
<id>server2</id>
<privateKey>wang</username>
<passphrase>456</passphrase>
</server>
</servers>

镜像(mirrors/mirror*):用<mirrorOf>配置覆盖一个或者多个仓库的配置。

<mirrorOf>元素:

  * = everything

  external:* = everything not on the localhost and not file based.

  repo,repo1 = repo or repo1

  *,!repo1 = everything except repo1

优点:1.速度快 2.使用自定义镜像可管控

<mirrors>
<mirror>
<!-- 镜像id,唯一标识 -->
<id>central-mirror</id>
<!-- 镜像名称 -->
<name>Maven China Mirror</name>
<!-- 镜像地址 -->
<url>http://search.maven.org/#browse</url>
<!-- 这个是谁的镜像,覆盖哪个仓库的配置 -->
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

环境差异文件(profiles/profile*):

<profiles>
<!--通过某些条件匹配来激活不同<profile>,如jdk、os、属性和属性值等等-->
<profile>
<!-- 唯一标识id -->
<id>jdk-1.6</id>
<!-- 激活条件 -->
<activation>
<jdk>1.6</jdk>
</activation>
<!-- 键值对属性 -->
<properties>
<property.key>property.value</property.key>
         <!--
            maven支持使用占位符的方式设置或获取值
            1.env:操作系统环境变量
            2.project.x:当前project的属性
            3.setttings.x:对应settings.xml文件的属性
            4.properties文件中的属性(redis.ip=10.11.12.13):redis.ip
            5.x:<properties>中设置的属性
          -->
                <anykey>${env.path}</anykey>
</properties>
            <!-- 仓库配置 -->
<repositories>
<repository>
<id>仓库id</id>
<name>仓库名称</name>
<url>仓库url</url>
<layout>在Maven 2/3中都是default,只有在Maven 1.x中才是legacy,默认也是default</layout>
<!-- 发布的稳定版本 -->
<releases>
<checksumPolicy>当组件校验失败时,warn或fail</checksumPolicy>
<enabled>是否使用此库下载组件</enabled>
<updatePolicy>当组件在本地不存在时的更新策略:always、daily(default)、interval:xx(in minutes)、never</updatePolicy>
</releases>
<!-- 快照版本,注释同上 -->
<snapshots>
<checksumPolicy></checksumPolicy>
<enabled></enabled>
<updatePolicy></updatePolicy>
</snapshots>
</repository>
</repositories>
<!-- 插件仓库 -->
<pluginRepositories>
<pluginRepository>
<!-- 配置与repository类似 -->
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

激活某个差异文件(activeProfiles/activeProfile*):

<!-- 指定某个profile生效 -->
<activeProfiles>
<activeProfile>对应profile id</activeProfile>
</activeProfiles>

当插件groupId没有显示提供,使用此groupId进行查找(pluginGroups/pluginGroup*):

<pluginGroups>
<!-- 当插件groupId没有显示提供,使用此groupId查找插件 -->
<!-- 官网:(Many) List of groupIds to search for a plugin when that plugin groupId is not explicitly provided. -->
<pluginGroup>org.mortbay.jetty</pluginGroup>
<pluginGroup>org.codehaus.cargo</pluginGroup>
</pluginGroups>

maven学习(一)setting.xml配置文件详解的更多相关文章

  1. 【maven学习】pom.xml文件详解

    环境 apache-maven-3.6.1 jdk 1.8 eclipse 4.7 POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示, ...

  2. Maven之(六)setting.xml配置文件详解

    setting.xml配置文件 maven的配置文件settings.xml存在于两个地方: 1.安装的地方:${M2_HOME}/conf/settings.xml 2.用户的目录:${user.h ...

  3. Maven之setting.xml配置文件详解

    setting.xml配置文件 maven的配置文件settings.xml存在于两个地方: 1.安装的地方:${M2_HOME}/conf/settings.xml 2.用户的目录:${user.h ...

  4. 【maven学习】settings.xml文件详解

    环境 apache-maven-3.6.1 jdk 1.8 eclipse 4.7 Settings.xml是设置maven参数的配置文件,包含类似本地仓储位置.修改远程仓储服务器.认证信息等配置.p ...

  5. Maven系列二setting.xml 配置详解

    文件存放位置 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: ${user.home}/.m2/settings.xml note:用户配置优先于全局配置.${use ...

  6. Maven中的pom.xml配置文件详解

    原文:http://blog.csdn.net/u012152619/article/details/51485297 <project xmlns="http://maven.apa ...

  7. 6.Maven之(六)setting.xml配置文件详解

    转自:https://blog.csdn.net/u012152619/article/details/51485152

  8. Java数据持久层框架 MyBatis之API学习四(xml配置文件详解)

    摘录网址: http://blog.csdn.net/u010107350/article/details/51292500 对于MyBatis的学习而言,最好去MyBatis的官方文档:http:/ ...

  9. struts2学习笔记--struts.xml配置文件详解

    这一节主要讲解struts2里面的struts.xml的常用标签及作用: 解决乱码问题 <constant name="struts.i18n.encoding" value ...

随机推荐

  1. P4174 [NOI2006]最大获利

    传送门 把用户群和中转站都看成点 用户群权值为正,中转站权值为负 为了获得用户群的权值,我们不得不一起获得中转站负的权值 发现就是裸的最大权闭合子图 那么从用户群连边向中转站,边值INF 从 S 连向 ...

  2. UML-2-迭代、进化和敏捷

    1.UP UP:Unified Process,统一过程.RUP:Rational Unified Process,Rational 公司制定的UP,是对UP的精细化. UP的过程: 初始 不是需求, ...

  3. Python学习 day07

    一.关于解决问题的思路 1.删除列表中索引为单数的元素. 别人的思路: 利用切片 li = [11, 22, 33, 44, 55] li = li[::2] print(li) 思考:虽然学了pyt ...

  4. spark第七篇:Spark SQL, DataFrame and Dataset Guide

    预览 Spark SQL是用来处理结构化数据的Spark模块.有几种与Spark SQL进行交互的方式,包括SQL和Dataset API. 本指南中的所有例子都可以在spark-shell,pysp ...

  5. Activemq API使用(不整合spring)

    首先需要引入activemq的jar包,这里用的是5.14.4版本的 <!-- https://mvnrepository.com/artifact/org.apache.activemq/ac ...

  6. 【3dsMax安装失败,如何卸载、安装3dMax 2011?】

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  7. 基于前端js模板替换的多语言方案思考

    最近在做将一个系统多语言化的项目,系统使用的是ASP.NET,直接使用了一种已有的方案:在页面渲染时采用正则表达式替换{XXX:001 确定}格式的标记.但是这个方式增加了服务端的字符串处理,对页面性 ...

  8. STL:vector用法总结

    一:介绍 vector是C++标准模板库,是一个容器,底层是数组,为连续内存.命名空间为std,所属头文件为<vector>   注意:不是<vector.h>vector存储 ...

  9. java将list分为指定大小的新集合

    上代码: import java.util.ArrayList; import java.util.List; public class JayCommonUtil { /** * 按指定大小,分隔集 ...

  10. [Activator-HelloAkka] Define our Actors

    The Actor is the unit of execution in Akka. Actors are object-oriented in the sense that they encaps ...