天天看點

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,如需轉載請自行聯系原作者