天天看点

sonatype nexus 搭建maven服务器二

一、nexus的安装:

1、配置环境变量:

Path=%MEXUS_HOME%\bin;......

2、验证环境变量是否配置成功:

cmd>nexus 出现如下界面说明环境变量配置成功。

<a href="http://s3.51cto.com/wyfs02/M00/7E/F2/wKiom1cNu1zDMREsAAALgXjbkCw345.png" target="_blank"></a>

3、安装服务:

cmd&gt;nexus install

4、启动nexus:

cmd&gt;nexus start

5、访问nexus:

http://localhost:8081/nexus/index.html

登录信息:admin=admin123

看到如下界面,大功告成!!!

<a href="http://s5.51cto.com/wyfs02/M02/7E/F0/wKioL1cNvY2gci9BAAFT_4Aj73g108.png" target="_blank"></a>

二、Maven仓库配置: 

1、maven的默认情况是首先访问“本地仓库”,本地没有直接访问“中央仓库”。

访问中央仓库的配置是在D:\tool\apache-maven-3.0.4\lib\maven-model-builder-3.0.4.jar的pom.xml中。

&lt;repositories&gt; 

 &lt;repository&gt;

  &lt;id&gt;central&lt;/id&gt; 

  &lt;name&gt;Central Repository&lt;/name&gt; 

  &lt;url&gt;http://repo.maven.apache.org/maven2&lt;/url&gt; 

  &lt;layout&gt;default&lt;/layout&gt;

  &lt;snapshots&gt; 

   &lt;enabled&gt;false&lt;/enabled&gt; 

  &lt;/snapshots&gt;  

  &lt;/repository&gt; 

&lt;/repositories&gt;

2、可以通过配置maven的setting.xml文件的profile,实现首先访问“本地仓库”,本地仓库没有访问“私有Nexus仓库”,“私有Nexus仓库”没有才访问“中央仓库”。

)配置profile:

  &lt;profile&gt;

      &lt;id&gt;nexusProfile&lt;/id&gt;

      &lt;repositories&gt;

        &lt;repository&gt;

          &lt;id&gt;nexus&lt;/id&gt;

          &lt;name&gt;nexus Repository&lt;/name&gt;

          &lt;url&gt;http://localhost:8081/nexus/content/groups/public/&lt;/url&gt;

        &lt;!--默认snapshot是关闭的,需要手工开启--&gt;

        &lt;snapshots&gt;

            &lt;enabled&gt;true&lt;/enabled&gt;

        &lt;/snapshots&gt;

        &lt;/repository&gt;

      &lt;/repositories&gt;

    &lt;/profile&gt;

2.)配置activeProfile(激活profile):

     &lt;activeProfile&gt;nexusProfile&lt;/activeProfile&gt;

3、可以通过配置maven的setting.xml文件的mirror,实现首先访问“本地仓库”,本地仓库没有访问“私有Nexus仓库”,“私有Nexus仓库”没有“不”访问“中央仓库”。

   &lt;mirror&gt;

      &lt;id&gt;nexusmirror&lt;/id&gt;

      &lt;mirrorOf&gt;*&lt;/mirrorOf&gt;

      &lt;name&gt;Human Readable Name for this Mirror.&lt;/name&gt;

      &lt;url&gt;http://localhost:8081/nexus/content/groups/public/&lt;/url&gt;

    &lt;/mirror&gt;

注意:只要mirrorOf的工厂(如nexus、central)要访问,都会自动来找镜像mirror,如果mirror无法访问到就不会再去中央工厂访问,使用*表示所有的工厂都使用这个镜像访问,使用*这是推荐的做法。

本文转自lzf0530377451CTO博客,原文链接: http://blog.51cto.com/8757576/1763346,如需转载请自行联系原作者