1. 程式人生 > >配置兩臺電腦maven共用一個nexus私服

配置兩臺電腦maven共用一個nexus私服

       雖然最近一直在用maven,但是由於學校網速尚可,所以對私服的需求不不高,所以一直都沒有搭建過nexus。現在新買了一臺筆記本,覺得剛好可以搭建個私服,給兩臺電腦的maven都可以使用到nexus。順便學習下如何搭建nexus。

      具體操作如下:

                 選擇合適自己系統版本的即可

       三、 搭建nexus倉庫,現在的安裝nexus並不需要tomcat了(因為它內建了一個Jetty),直接進入到nexus的解壓路徑中的,nexus-2.8.0-05-bundle\nexus-2.8.0-05\bin\jsw資料夾中,選擇自己系統對應的版本,由於作則的是win 8.1  64位。所以選擇windows-x86-64,然後點選 install-nexus.bat 即可。到此,nexus安裝完畢。

       四、配置nexus

             1、 在瀏覽器中輸入地址:http://127.0.0.1:8081/nexus/#welcome,開啟。

             2、在右上角處,點選 log in。輸入賬號admin,密碼admin123.,登陸

             3、在左邊處選擇“Repositories”,如圖

             4、分別雙擊這三個

 ,每個都選擇

儲存,然後三個分別右擊,選擇Repaire index。

           5、配置maven

                    a.在maven安裝目錄下找到conf資料夾,修改setting.xml資料夾,新增上<localRepository>H:\maven_jar</localRepository>,標籤裡面的為以後maven所為你下載jar包的路徑。

                    b.在最後一行</setting>前新增下面一段

<mirrors>  
        <mirror>  
            <id>nexus</id>  
            <url>http://localhost:8081/nexus/content/groups/public</url>  
            <mirrorOf>*</mirrorOf>  
        </mirror>  
    </mirrors>  
 <profile>
     <id>nexus</id>
     <repositories>
       <repository>
           <id>nexus</id>
           <name>local private nexus</name>
           <url>http://localhost:8081/nexus/content/groups/public</url>
       </repository>
     </repositories>
   </profile>
   <profile>
     <id>nexus-snapshots</id>
     <repositories>
       <repository>
           <id>nexus-snapshots</id>
           <name>local private nexus snapshots</name>
           <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
       </repository>
     </repositories>
   </profile>
  </profiles>
<activeProfiles>
    <activeProfile>nexus</activeProfile>
    <activeProfile>nexus-snapshots</activeProfile>
</activeProfiles>

其中,不準備安裝的nexus的那臺電腦,要把上面的的ip地址修改為安裝有nexus的電腦的地址。比如我的兩臺電腦中,一臺是臺式,一臺是筆記本,其中臺式安裝nexus,而筆記本中並不安裝,所以,我希望的是,筆記本maven以後從桌上型電腦中的nexus中下載jar包(上傳的功能現在還並不需要)。所以,我把筆記本中的maven中的setting.xml中的修改成以下版本
<mirrors>  
        <mirror>  
            <id>nexus</id>  
            <url>http://10.0.22.234:8081/nexus/content/groups/public</url>  
            <mirrorOf>*</mirrorOf>  
        </mirror>  
    </mirrors>  
 <profile>
     <id>nexus</id>
     <repositories>
       <repository>
           <id>nexus</id>
           <name>local private nexus</name>
           <url>http://10.0.22.234:8081/nexus/content/groups/public</url>
       </repository>
     </repositories>
   </profile>
   <profile>
     <id>nexus-snapshots</id>
     <repositories>
       <repository>
           <id>nexus-snapshots</id>
           <name>local private nexus snapshots</name>
           <url>http://10.0.22.234:8081/nexus/content/groups/public-snapshots</url>
       </repository>
     </repositories>
   </profile>
  </profiles>
<activeProfiles>
    <activeProfile>nexus</activeProfile>
    <activeProfile>nexus-snapshots</activeProfile>
</activeProfiles>

到此,maven配置完成。

最後配置MyEclipse中的maven外掛和自己的maven關聯起來

windows--preference--MyEclipse--Maven4Myeclipse--installation--點選右邊的"Add",選擇自己maven的路徑。如圖


再選擇UserSetting,設定setting.xml的路徑。

檢測下結果,檢視nexus路徑下的nexus-2.8.0-05-bundle\sonatype-work\nexus\storage\central\jstl\jstl。沒有這個資料夾或者有這個資料夾但沒有東西。

然後在MyEclipse新建個maven專案裡面的pom檔案中新增依賴

<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.1.2</version>
		</dependency>

儲存,等maven執行完成後,會發現剛才所說的資料夾裡面會出現1.1.2資料夾。裡面有jar檔案。如果使用筆記本中的maven也是。