1、本地環境配置(Nexus3.6支持jdk版本1.6、1.7、1.8)
- 1.2、解壓得到目錄
- 1.3、將Nexus的bin目錄添加到Path環境變量中:
- 1.4、安裝啟動
打開cmd,一路cd到安裝目錄下的bin目錄,輸入命令:nexus /run 運行安裝
注:如果出現錯誤:java.lang.NumberFormatException: null,則可能是jdk版本不對,或路徑中帶中文
- 1.5、訪問瀏覽器(http://localhost:8081)
到此配置完畢,然后,即可在本地訪問Nexus,如出現下圖就表示配置成功:
2、Nexus中的倉庫
- 2.1、訪問的倉庫類型:
hosted 宿主倉庫:主要用於部署無法從公共倉庫獲取的構件以及自己或第三方的項目構件;
proxy 代理倉庫:代理公共的遠程倉庫;
group 倉庫組:Nexus 通過倉庫組統一管理多個倉庫,這樣我們在項目中直接請求倉庫組即可請求到倉庫組管理的多個倉庫。
簡單的說,就是你可以上傳私有的項目到hosted,以及配置proxy以獲取第三方的依賴(比如可以配置中央倉庫的地址)。前面兩個都弄好了之后,在通過group聚合給客戶提供統一的訪問地址。
- 2.2、管理本地倉庫
Nexus預定義了2個本地倉庫,分別是maven-releases, maven-snapshots, 分別講一下這二個預置的倉庫都是做什么用的:
maven-releases:這里存放我們自己項目中發布的構建, 通常是Release版本的。
maven-snapshots:這個倉庫非常的有用, 它的目的是讓我們可以發布那些非release版本, 非穩定版本。
- 2.3、增加倉庫(以增加宿主倉庫為例)
- 2.4、增加本地用戶
3、配置私服(settings.xml)
<!--設置的maven本地倉庫--> <localRepository>D:\install\maven\repository</localRepository> <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://192.168.10.68:8081/repository/maven-public/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--遠程倉庫列表,它是Maven用來填充構建系統本地倉庫所使用的一組遠程項目。 --> <repositories> <!--發布版本倉庫--> <repository> <id>nexus</id> <!--地址是nexus中repository(Releases/Snapshots)中對應的地址--> <url>http://192.168.10.68: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>
4、上傳jar包到Nexus
- 4.1、直接上傳jar(在cmd中輸入下列命令:)
mvn deploy:deploy-file -DgroupId=xxx.xxx -DartifactId=xxx -Dversion=xxx -Dpackaging=jar -Dfile=D:\xxx.jar -Durl=http://xxx.xxx.xxx.xxx:8081/repository/maven-releases/ -DrepositoryId=nexus
- 1
注釋:
-DgroupId 為上傳的jar的groupId -DartifactId 為上傳的jar的artifactId -Dversion 為上傳的jar的需要被依賴的時候的版本號 -Dpackaging為jar -Dfile為jar包路徑 -Durl 為要上傳的路徑,-DrepositoryId 為repository的唯一標示,跟第3步中賦權配置的server相同 注意:-Dfile中的路徑最好就在D盤的根目錄D:\xxx.jar,不要D:\xxx\xxx\xxx\xxx.jar,這樣可能會報錯
- 4.2、直接將項目發布到倉庫中
pom.xml中添加,和dependencies屬於同一級別,在project級別下
<distributionManagement> <repository> <id>nexus</id> <name>releases Repository</name> <url>http://192.168.10.68:8081/repository/maven-releases/</url> </repository> </distributionManagement>
添加完后,cd到pom.xml文件目錄中運行:mvn deploy即可
注:id為要上傳的repository的唯一標示,url為要上傳的repository的路徑
- 4.3、示例(第一種方法)
運行:
mvn deploy:deploy-file -DgroupId=org.olap4j -DartifactId=olap4j -Dversion=0.9.7.309-JS-3 -Dpackaging=jar -Dfile=D:\olap4j-0.9.7.309-JS-3.jar -Durl=http://192.168.10.68:8081/repository/maven-releases/ -DrepositoryId=nexus
- 1
查看倉庫結果: