一、nexus3的安裝和啟動
1.在官網下載nexus3
2.安裝nexus
解壓到指定文件夾D:\nexus3\,得到 nexus-3.16.2-01 文件夾和 sonatype-work 文件夾,nexus-3.16.2-01文件夾放的是nexus服務器相關的文件,sonatype-work放的是nexus工作的數據文件,上傳下載的jar包就在這個文件夾下面。
在命令提示符中進去D:\nexus3\nexus-3.16.2-01\bin文件夾,執行命令:nexus /run,訪問http://localhost:8081。
二、nexus3的使用
1.登錄nexus
使用默認用戶admin,密碼admin123,登錄。
2.管理本地倉庫
Nexus有3個類型的數據倉庫,分別是hosted,proxy,group。
hosted 宿主倉庫:主要用於部署無法從公共倉庫獲取的構件以及自己或第三方的項目構件;
proxy 代理倉庫:代理公共的遠程倉庫;
group 倉庫組:Nexus 通過倉庫組統一管理多個倉庫,這樣我們在項目中直接請求倉庫組即可請求到倉庫組管理的多個倉庫。
Nexus預定義了2個本地倉庫,分別是maven-releases, maven-snapshots。
maven-releases:這里存放我們自己項目中發布的構建, 通常是Release版本的。
maven-snapshots:這個倉庫非常的有用, 它的目的是讓我們可以發布那些非release版本, 非穩定版本。
我們還可以自己創建倉庫
如果是創建的proxy倉庫或者hosted倉庫,需要添加到公共倉庫里。
3.上傳本地jar包
4.在maven中配置私服,編輯setting.xml
<servers> <server> <!--這是server的id(注意不是用戶登陸的id),該id與distributionManagement中repository元素的id相匹配。 --> <id>nexus</id> <username>admin</username> <password>admin123</password> </server> </servers> <!--為倉庫列表配置的下載鏡像列表。 --> <mirrors> <mirror> <!--該鏡像的唯一標識符。id用來區分不同的mirror元素。 --> <id>nexus</id> <!--此處配置所有的構建均從私有倉庫中下載 *代表所有,也可以寫central --> <mirrorOf>*</mirrorOf> <name>central repository</name> <!--該鏡像的URL。構建系統會優先考慮使用該URL,而非使用默認的服務器URL。 --> <url>http://127.0.0.1:8081/repository/maven-public/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--遠程倉庫列表,它是Maven用來填充構建系統本地倉庫所使用的一組遠程項目。 --> <repositories> <!--發布版本倉庫--> <repository> <id>nexus</id> <!--地址是nexus中repository(Releases/Snapshots)中對應的地址--> <url>http://127.0.0.1:8081/repository/maven-public/</url> <!--true或者false表示該倉庫是否為下載某種類型構件(發布版,快照版)開啟。 --> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <!--激活配置--> <activeProfiles> <!--profile下的id--> <activeProfile>nexus</activeProfile> </activeProfiles>
通過命令行上傳jar到nexus:
mvn deploy:deploy-file -DgroupId=com.sgcc.ams -DartifactId=ams-base -Dversion=1.7.0 -Dpackaging=jar -Dfile=C:\develop\lib\ams-base-1.7.0.jar -Durl=http://127.0.0.1:8081/repository/maven-releases/ -DrepositoryId=nexus
在項目中配置私服,pom.xml中添加
<!--上傳到nexus倉庫中,配合mvn deploy:deploy--> <distributionManagement> <repository> <id>nexus</id> <name>Nexus snapshots Repository</name> <!--snapshots倉庫 --> <url>http://127.0.0.1:8081/repository/maven-snapshots/</url> </repository> </distributionManagement>
通過命令行執行mvn deploy即可。
內容部分參考:
https://blog.csdn.net/cool_summer_moon/article/details/78779530
https://blog.csdn.net/u013887008/article/details/79429973