一、简介

settings.xml对于maven来说相当于全局性的配置,用于所有的项目,当Maven运行过程中的各种配置,例如pom.xml,不想绑定到一个固定的project或者要分配给用户时,我们使用settings.xml中的settings元素来确定这些配置。这包含了本地仓库位置,远程仓库服务器以及认证信息等。

settings.xml存在于两个地方:

1.安装的地方:$M2_HOME/conf/settings.xml

2.用户的目录:${user.home}/.m2/settings.xml

前者又被叫做全局配置,后者被称为用户配置。如果两者都存在,它们的内容将被合并,并且用户范围的配置优先。

平时配置时优先选择用户目录的settings.xml

下面是settings下的顶层元素的一个概览:

 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>

二、简单值

localRepository:这个值是构建系统的本地仓库的路径。默认的值是${user.home}/.m2/repository.如果一个系统想让所有登陆的用户都用同一个本地仓库的话,这个值是极其有用的。

interactiveMode:如果Maven要试图与用户交互来得到输入就设置为true,否则就设置为false,默认为true。

usePluginRegistry:如果Maven使用${user.home}/.m2/plugin-registry.xml来管理plugin的版本,就设置为true,默认为false。

offline:如果构建系统要在离线模式下工作,设置为true,默认为false。如果构建服务器因为网络故障或者安全问题不能与远程仓库相连,那么这个设置是非常有用的。

三、PluginGroups(插件组)

这个元素包含了一系列pluginGroup元素,每个又包含了一个groupId。当一个plugin被使用,而它的groupId没有被提供的时候,这个列表将被搜索。这个列表自动的包含了org.apache.maven.plugins和org.codehaus.mojo。

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
...
</settings>

四、Servers(服务器)

1. 定义jar包下载的Maven仓库

2. 定义部署服务器

<servers>
<server>
<id>tomcat</id>
<username>bruce</username>
<password>password</password>
</server>
<server>
<id>shiyue</id>
<username>admin</username>
<password>password</password>
</server>
</servers>

tomcat: 部署服务器

shiyue: Mave私服

五、Mirrors(镜像)

指定仓库的地址,则默认从指定的镜像下载jar包及插件

<mirrors>

     <mirror>
<id>mirrorId</id>
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://host:port/nexus-2.1.2/content/groups/public</url>
</mirror>
</mirrors>

六、Proxies(代理)

有时候你所在的公司基于安全因素考虑,要求你使用通过安全认证的代理访问因特网。这时就需要为Maven配置HTTP代理。

<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
            http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository/>
    <interactiveMode/>
    <usePluginRegistry/>
    <offline/>
    <pluginGroups/>
    <servers/>
    <mirrors/>
    <proxies/>
    <profiles/>
    <activeProfiles/>
</settings>

二、简单值

localRepository:这个值是构建系统的本地仓库的路径。默认的值是${user.home}/.m2/repository.如果一个系统想让所有登陆的用户都用同一个本地仓库的话,这个值是极其有用的。

interactiveMode:如果Maven要试图与用户交互来得到输入就设置为true,否则就设置为false,默认为true。

usePluginRegistry:如果Maven使用${user.home}/.m2/plugin-registry.xml来管理plugin的版本,就设置为true,默认为false。

offline:如果构建系统要在离线模式下工作,设置为true,默认为false。如果构建服务器因为网络故障或者安全问题不能与远程仓库相连,那么这个设置是非常有用的。

三、PluginGroups(插件组)

这个元素包含了一系列pluginGroup元素,每个又包含了一个groupId。当一个plugin被使用,而它的groupId没有被提供的时候,这个列表将被搜索。这个列表自动的包含了org.apache.maven.plugins和org.codehaus.mojo。

1
2
3
4
5
6
7
8
9
10
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
            http://maven.apache.org/xsd/settings-1.0.0.xsd">
    ...
    <pluginGroups>
        <pluginGroup>org.mortbay.jetty</pluginGroup>
    </pluginGroups>
    ...
</settings>

四、Servers(服务器)

1. 定义jar包下载的Maven仓库

2. 定义部署服务器

1
2
3
4
5
6
7
8
9
10
11
12
<servers>
    <server>
        <id>tomcat</id>
        <username>bruce</username>
        <password>password</password>
    </server>
    <server>
        <id>shiyue</id>
        <username>admin</username>
        <password>password</password>
    </server>
  </servers>

tomcat: 部署服务器

shiyue: Mave私服

五、Mirrors(镜像)

指定仓库的地址,则默认从指定的镜像下载jar包及插件

1
2
3
4
5
6
7
8
9
<mirrors>
                                                                                                 
     <mirror>
      <id>mirrorId</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://host:port/nexus-2.1.2/content/groups/public</url>
    </mirror>
  </mirrors>

六、Proxies(代理)

有时候你所在的公司基于安全因素考虑,要求你使用通过安全认证的代理访问因特网。这时就需要为Maven配置HTTP代理。

1
2
3
4
5
6
7
8
9
10
11
12
<proxies>
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
 </proxies>

Maven实战(七)settings.xml相关配置的更多相关文章

  1. (转)Maven实战(七)settings.xml相关配置

    一.简介 settings.xml对于maven来说相当于全局性的配置,用于所有的项目,当Maven运行过程中的各种配置,例如pom.xml,不想绑定到一个固定的project或者要分配给用户时,我们 ...

  2. Maven项目settings.xml的配置

    原文地址 http://www.cnblogs.com/DreamDrive/p/5571916.html 在Maven中提供了一个settings.xml文件来定义Maven的全局环境信息.这个文件 ...

  3. maven全局配置文件settings.xml详解

    概要 settings.xml有什么用? 如果在Eclipse中使用过Maven插件,想必会有这个经验:配置settings.xml文件的路径. settings.xml文件是干什么的,为什么要配置它 ...

  4. [转]maven全局配置文件settings.xml详解

    概要 settings.xml有什么用? 如果在Eclipse中使用过Maven插件,想必会有这个经验:配置settings.xml文件的路径. Paste_Image.png settings.xm ...

  5. 大数据入门:Maven项目的创建及相关配置

    目录 Maven项目的创建及相关配置 一.Maven的介绍 1.Maven是什么: 2.Maven作用: 3.Maven项目的目录结构: 4.Maven的三点坐标: 5.maven的pom文件: 6. ...

  6. Maven(四-1) Maven的配置文件settings.xml

    转载于:http://www.cnblogs.com/yakov/archive/2011/11/26/maven2_settings.html 概览 当Maven运行过程中的各种配置,例如pom.x ...

  7. maven学习7 settings.xml解析

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

  8. [转]Maven 全局配置文件settings.xml详解

    原文地址:https://www.jianshu.com/p/110d897a5442 概要 settings.xml有什么用? 如果在Eclipse中使用过Maven插件,想必会有这个经验:配置se ...

  9. Maven的配置文件-settings.xml内容分解

    本文转载:https://www.cnblogs.com/jingmoxukong/p/6050172.html 概要 settings.xml有什么用? 如果在Eclipse中使用过Maven插件, ...

随机推荐

  1. 详解Adorner Layer(zz)

    首先,千万不要觉得Adorner离你很远,因为最简单的WPF界面也会用到Adorner.在WPF中,下面的几个很常见的功能,都是用Adorner实现的.     1. 光标(caret)     2. ...

  2. javascript,HTML,PHP,ASP做301跳转代码 SEO优化设置

    URL HTTP Redirection URL http redirection is an automatic URL change operation from one URL to anoth ...

  3. 关于 List<T>

    System.Object   System.Collections.Generic.List<T>   list<string,string>,这种形式本身就是错误的,你可以 ...

  4. JAVA获取两个List<String>中不同的数据

    效率非常不错 测试结果: 1.list1中有97277条数据,list2中有37894条数据,两个list进行对比找出不同的数据共60000条左右,用时:0.051秒 2.list1中有97277条数 ...

  5. 【BZOJ】1601: [Usaco2008 Oct]灌水(kruskal)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小 ...

  6. python模块之codecs

    http://blog.csdn.net/suofiya2008/article/details/5579413  

  7. 提升 web 应用程序的性能(一)

       提升 web 应用程序的性能,找出瓶颈,加快客户端内容的速度.    作为 web 用户,我们知道页面加载或刷新的速度对其成功至关重要.本文将帮助您更好地理解影响 web 应用程序性能的因素.学 ...

  8. JS function的参数问题

    1.当传入的参数个数小于声明的参数个数时,缺少的参数值就是:undefined 类似方法重载 var f1 = function(p1,p2,p3){     switch(arguments.len ...

  9. 利用Python的三元表达式解决Odoo中工资条中城镇、农村保险的问题

    Python中没有像C#中有三元表达式 A?B:C 但在python中可以通过 A if condition else B 的方式来达到同样的效果. 例如 : 1 if True else 0 输出 ...

  10. MUI - Scroll插件的使用

    http://dev.dcloud.net.cn/mui/ui/#scroll 神坑1:如果在vuejs中使用,那么需要配合mui.ready(function(){}) 才能找到dom对象,具体de ...