搭建Maven和Nexus環境

壹頁書發表於2016-01-07
下載Maven和Nexus
apache-maven-3.3.9
nexus-2.12.0-01

解壓nexus,進入目錄
D:\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin>
安裝服務
D:\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin>nexus.bat install
啟動服務
D:\nexus-2.12.0-01-bundle\nexus-2.12.0-01\bin>nexus.bat start
wrapper  | Starting the nexus service...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | Waiting to start...
wrapper  | nexus started.

訪問如下地址測試Nexus私服是否安裝成功
http://127.0.0.1:8081/nexus

管理員的預設密碼是
admin/admin123

同步Maven中央庫的索引檔案


修改配置,下載遠端的索引


然後Repair索引.


可以看到正在執行的RepairIndex的任務.



在專案的pom.xml檔案中,配置私服地址

  1.     <repositories>
  2.         <repository>
  3.             <id>nexus</id>
  4.             <name>Team Nexus Repository</name>
  5.             <url>http://localhost:8081/nexus/content/groups/public</url>
  6.         </repository>
  7.     </repositories>
  8.     <pluginRepositories>
  9.         <pluginRepository>
  10.             <id>nexus</id>
  11.             <name>Team Nexus Repository</name>
  12.             <url>http://localhost:8081/nexus/content/groups/public</url>
  13.         </pluginRepository>
  14.     </pluginRepositories>

或者拷貝maven/conf/settings.xml檔案到使用者家目錄的.m2資料夾下
修改該檔案
  1.     <mirrors>
  2.             <mirror>
  3.                 <id>central</id>
  4.                 <mirrorOf>*</mirrorOf> <!-- * 表示讓所有倉庫使用該映象-->
  5.                 <name>central-mirror</name>
  6.                 <url>http://localhost:8081/nexus/content/groups/public/</url>
  7.             </mirror>
  8.     </mirrors>

如果需要從本地釋出jar包到私服
需要先在私服上建立一個賬號


設定使用者,注意許可權


然後在專案的pom中加入如下配置

  1.     <distributionManagement>
  2.         <repository>
  3.             <id>deployment</id>
  4.             <name>Nexus Release Repository</name>
  5.             <url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
  6.         </repository>
  7.         <snapshotRepository>
  8.             <id>deployment</id>
  9.             <name>Nexus Snapshot Repository</name>
  10.             <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
  11.         </snapshotRepository>
  12.     </distributionManagement>

然後修改家目錄.m2檔案下的settings.xml檔案
  1. <servers>
  2.         <server>
  3.             <id>deployment</id>
  4.             <username>dev</username>
  5.             <password>123456</password>
  6.         </server>        
  7. </servers>

標紅的ID需要一致.

這時候執行如下命令
E:\workspace\test>mvn clean deploy
就可以將jar包直接釋出在私服了.

參考:
http://tianweili.github.io/blog/2015/03/17/linux-nexus-maven-private-server/


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29254281/viewspace-1973387/,如需轉載,請註明出處,否則將追究法律責任。

相關文章