maven項目部署到Repository(Nexus)

目錄[-]html

   

           

本文將以開源的Nexus爲例,演示如何將本身開發的項目部署到Nexus Repository中,解決項目發佈、升級的問題。 spa

(一)下載並安裝Nexus

    Nexus只需下載war包放到tomcat服務器上即可。
.net



(二)配置Nexus Repository

  1. 打開WEB管理界面:http://localhost:8081/nexus/index.htmlcode

  2. 點擊右上角Log In進行登陸,默認賬號:admin、密碼:admin123server

  3. 點擊左側Repositories項 -> central倉庫 -> Configuration -> Download Remote Indexes=True -> Save,表示下載遠程倉庫的索引。

  4. 右鍵central倉庫 -> Update Index,更新遠程倉庫索引到本地,這一步可以加速本地索引。


   說明:

  • 新搭建的neuxs環境只是一個空的倉庫, 須要手動和遠程中心庫進行同步,nexus默認是關閉遠程索引下載,最重要的一件事情就是開啓遠程索引下載。 找到右邊倉庫列表中的三個倉庫Apache Snapshots,Codehaus Snapshots和Maven Central,而後再沒有倉庫的configuration下把Download Remote Indexes修改成true。而後在這三個倉庫上分別右鍵,選擇Repari Index,這樣Nexus就會去下載遠程的索引文件。右鍵倉庫 -> Update Index,更新遠程倉庫索引到本地,這一步可以加速本地索引

  • 新建公司的內部倉庫,步驟爲 Repositories –> Add –> Hosted Repository,在頁面的下半部分輸入框中填入Repository ID和Repository Name便可,另外把Deployment Policy設置爲Allow Redeploy

  • Nexus中倉庫組的概念是Maven沒有 的,在Maven看來,無論你是hosted也好,proxy也好,或者group也好,對我都是同樣的,我只管根據 groupId,artifactId,version等信息向你要構件。爲了方便Maven的配置,Nexus可以將多個倉庫,hosted或者 proxy合併成一個group,這樣,Maven只須要依賴於一個group,便能使用全部該group包含的倉庫的內容。


(三)在項目中配置Nexus Repository的信息

  • 項目pom文件配置distributionManagement

?

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

  • settings.xml配置帳號密碼。注意server的id與repository的id必須對應

?

1
2
3
4
5
6
7
8
9
10
11
12
    < servers >
     < server >
         < id >releases</ id >
         < username >admin</ username >
         < password >admin123</ password >
     </ server >
     < server >
         < id >snapshots</ id >
         < username >admin</ username >
         < password >admin123</ password >
     </ server >
</ servers >



(四)發佈到Nexus Repository

  • 項目中執行mvn deploy,成功以下所示

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ tenpay ---

Uploading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.jar
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.pom
Uploaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.pom (2 KB at 9.7 KB/sec)
Uploaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/1.2/tenpay-1.2.jar (39 KB at 124.4 KB/sec)
Downloading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml
Downloaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml (347 B at 4.3 KB/sec)
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml
Uploaded: http://localhost:8081/nexus/content/repositories/releases/com/capital/tenpay/maven-metadata.xml (376 B at 7.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

相關文章
相關標籤/搜索