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. I/O设备

    I/O(Input/Output)设备是指与计算机进行数据传输的硬件,具体分为字符设备.块设备.网络设备. 字符设备 字符设备(character device),又叫做人机交互设备.用户通过这些设备 ...

  2. Android Studio 常用应用

    1.在控制台的Logcat中输出测试语句 package com.example.lucky.helloworld; import android.support.v7.app.AppCompatAc ...

  3. Hero

    Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Description When pl ...

  4. CH2401 送礼物 双向搜索

    双向搜索:把前一半的可行状态搜出来,然后sort+unique,之后搜后一半时,结束时二分一下前一半的答案,拼出一个与W尽量接近的ans来更新 ps:距LYD说前一半取n/2+2时跑的最快...不知, ...

  5. P2762 太空飞行计划问题

    传送门 经典的最大权闭合子图问题 实验有正的价值,仪器的价值为负 为了实验我们必须选择相应的仪器 所以从 S 连向实验,边权为实验的价值 实验与相应仪器之间连边,边权为 INF 仪器连向 T 边权为仪 ...

  6. 116th LeetCode Weekly Contest Maximum Width Ramp

    Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j].  The ...

  7. UESTC - 1607 ad-hoc

    #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=j;i<=k;i++) using namespace s ...

  8. 马的移动(BFS) 详细注释 一个具有情怀的题目

    题目描述 小明很喜欢下国际象棋,一天,他拿着国际象棋中的"马"时突然想到一个问题: 给定两个棋盘上的方格a和b,马从a跳到b最少需要多少步? 现请你编程解决这个问题. 提示:国际象 ...

  9. maria(mysql)的主从复制

    一.mariadb的基本操作 1.远程连接 mysql -uroot -p -h 127.0.0.1 mysql -uroot -p -h 192.168.226.128 2.赋予远程连接的权限 gr ...

  10. TensorFlow-多层感知机(MLP)

    TensorFlow训练神经网络的4个步骤: 1.定义算法公式,即训练神经网络的forward时的计算 2.定义损失函数和选择优化器来优化loss 3.训练步骤 4.对模型进行准确率评测 附Multi ...