日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

快速学习Maven-从私服下载 jar 包Nexus

發布時間:2024/3/12 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 快速学习Maven-从私服下载 jar 包Nexus 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
需求

沒有配置 nexus 之前,如果本地倉庫沒有,去中央倉庫下載,通常在企業中會在局域網內部署一臺私服服務器,有了私服本地項目首先去本地倉庫找 jar,如果沒有找到則連接私服從私服下載 jar 包,如果私服沒有 jar 包私服同時作為代理服務器從中央倉庫下載 jar 包,這樣做的好處是一方面由私服對公司項目的依賴 jar 包統一管理,一方面提高下載速度,項目連接私服下載 jar 包的速度要比項目連接中央倉庫的速度快的多。

管理倉庫組

nexus中包括很多倉庫,hosted中存放的是企業自己發布的jar包及第三方公司的jar包,proxy 中存放的是中央倉庫的 jar,為了方便從私服下載 jar 包可以將多個倉庫組成一個倉庫組,每個工程需要連接私服的倉庫組下載 jar 包。

打開 nexus 配置倉庫組,如下圖:

上圖中倉庫組包括了本地倉庫、代理倉庫等。

在 setting.xml 中配置倉庫

在客戶端的 setting.xml 中配置私服的倉庫,由于 setting.xml 中沒有 repositories 的配置標簽需要使用 profile 定義倉庫。

<profile><!--profile 的 id--><id>dev</id><repositories><repository><!--倉庫 id,repositories 可以配置多個倉庫,保證 id 不重復--><id>nexus</id><!--倉庫地址,即 nexus 倉庫組的地址--><url>http://localhost:8081/nexus/content/groups/public/</url><!--是否下載 releases 構件--><releases><enabled>true</enabled></releases><!--是否下載 snapshots 構件--><snapshots><enabled>true</enabled></snapshots></repository></repositories><pluginRepositories><!-- 插件倉庫,maven 的運行依賴插件,也需要從私服下載插件 --><pluginRepository><!-- 插件倉庫的 id 不允許重復,如果重復后邊配置會覆蓋前邊 --><id>public</id><name>Public Repositories</name><url>http://localhost:8081/nexus/content/groups/public/</url></pluginRepository></pluginRepositories></profile>

使用 profile 定義倉庫需要激活才可生效。

<activeProfiles><activeProfile>dev</activeProfile></activeProfiles>

配置成功后通過 eclipse 查看有效 pom,有效 pom 是 maven 軟件最終使用的 pom 內容,程序員不直接編輯有效 pom,打開有效 pom


有效 pom 內容如下:
下邊的 pom 內容中有兩個倉庫地址,maven 會先從前邊的倉庫的找,如果找不到 jar 包再從下邊的找,從而就實現了從私服下載 jar 包。

<repositories><repository><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots><id>public</id><name>Public Repositories</name><url>http://localhost:8081/nexus/content/groups/public/</url></repository><repository><snapshots><enabled>false</enabled></snapshots><id>central</id><name>Central Repository</name><url>https://repo.maven.apache.org/maven2</url></repository></repositories><pluginRepositories><pluginRepository><id>public</id><name>Public Repositories</name><url>http://localhost:8081/nexus/content/groups/public/</url></pluginRepository><pluginRepository><releases><updatePolicy>never</updatePolicy></releases><snapshots><enabled>false</enabled></snapshots><id>central</id><name>Central Repository</name><url>https://repo.maven.apache.org/maven2</url></pluginRepository></pluginRepositories>
測試從私服下載 jar 包

測試 1:局域網環境或本地網絡即可
在 ssm_service 工程中添加以上配置后,添加 ssm_dao 工程的依賴,刪除本地倉庫中 ssm_dao工程,同時在 eclipse 中關閉 ssm_dao 工程。觀察控制臺:

項目先從本地倉庫找 ssm_dao,找不到從私服找,由于之前執行 deploy 將 ssm_dao 部署到私服中,所以成功從私服下載 ssm_dao 并在本地倉庫保存一份。如果此時刪除私服中的 ssm_dao,執行 update project 之后是否正常?如果將本地倉庫的 ssm_dao 和私服的 ssm_dao 全部刪除是否正常?

測試 2:需要互聯網環境

在項目的 pom.xml 添加一個依賴,此依賴在本地倉庫和私服都不存在,maven 會先從本地倉庫找,本地倉庫沒有再從私服找,私服沒有再去中央倉庫下載,jar 包下載成功在私服、本地倉庫分別存儲一份。

總結

以上是生活随笔為你收集整理的快速学习Maven-从私服下载 jar 包Nexus的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。