设为首页 收藏本站
查看: 1376|回复: 0

[经验分享] Maven实战(七)settings.xml相关配置

[复制链接]

尚未签到

发表于 2017-3-2 11:38:38 | 显示全部楼层 |阅读模式
  一、简介
  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下的顶层元素的一个概览:



1 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
2          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
4             http://maven.apache.org/xsd/settings-1.0.0.xsd">
5     <localRepository/>
6     <interactiveMode/>
7     <usePluginRegistry/>
8     <offline/>
9     <pluginGroups/>
10     <servers/>
11     <mirrors/>
12     <proxies/>
13     <profiles/>
14     <activeProfiles/>
15 </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>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-349278-1-1.html 上篇帖子: Active MQ C#实现 下篇帖子: Red5边源服务器集群部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表