標籤:setting epo 使用 use 上下 命令 3.0 man 解壓縮
一、安裝
1、從網上下載nexus軟體
https://www.sonatype.com/download-oss-sonatype 下載Nexus Repository Manager OSS軟體包
目前我使用的是3.0的版本,下面均是以安裝3.0的版本位例子
2、將下載下來的nexus-3.13.0-01-win64.zip解壓縮到目標路徑,官網建議windows不要放在Program files 下,那麼本人放在D:/develop下面
3、
(1) 未註冊成系統服務,直接運行:
a)進入bin目錄,運行cmd 命令 :nexus.exe /run 此時運行私人倉庫;linux版本可以執行:nexus /run
b)按ctrl-c可以停止運行私服;
(2) 註冊成系統服務(需要確保jdk已經在系統中安裝過):
a) 進入bin目錄,運行cmd:nexus.exe /install 此時會安裝私人倉庫;
b) 安裝完成之後,預設訪問連接埠未8081,上下文為 /
c) 進入頁面之後,直接登入,帳號:admin admin123
d) 在訪問的時候,請使用ip訪問
4、關於Nexus Repository Manager 更多介紹 可參考網址:https://help.sonatype.com
二、配置
按照以上的方法搭建好私服之後,此時需要對私服裡面的內容進行配置,使用者通用瀏覽器(http://127.0.0.1:8001/)訪問私服。
1、以管理員身份登入私服
在首頁的右上方點擊"Sign In" 進入登入頁面,帳號為:admin 密碼為:admin123;
2、配置代理倉庫
本地maven(已安裝Maven軟體)setting.xml 中在沒有私服的情況下,需要配置各種代理或鏡像(通過這些將需要的第三方提供的jar包下載到本地倉庫供maven工程直接引用)。但是由於網速原因或在不同電腦項目中都需要串連網路通過鏡像將所需jar包下載下來,一方面速度較慢,另一方面不好管理。因此需要私服,讓setting.xml直接配置私服的倉庫地址即可。
(1) 在私服中配置各種市面上常見的倉庫地址(增加新的代理源)
Cache統一設定為200天 288000
1. aliyunhttp://maven.aliyun.com/nexus/content/groups/public2. apache_snapshothttps://repository.apache.org/content/repositories/snapshots/3. apache_releasehttps://repository.apache.org/content/repositories/releases/4. atlassianhttps://maven.atlassian.com/content/repositories/atlassian-public/5. central.maven.orghttp://central.maven.org/maven2/6. datanucleushttp://www.datanucleus.org/downloads/maven27. maven-central (安裝後內建,僅需設定Cache有效期間即可)https://repo1.maven.org/maven2/8. nexus.axiomalaska.comhttp://nexus.axiomalaska.com/nexus/content/repositories/public9. oss.sonatype.orghttps://oss.sonatype.org/content/repositories/snapshots10.pentahohttps://public.nexus.pentaho.org/content/groups/omni/11. spring-snapshotshttps://repo.spring.io/snapshot//在配置這個代理源的時候,Version pollcy 要設定成 Snapshot,Layout pollcy 要設定成 Permissive.12. spring-milestoneshttps://repo.spring.io/milestone
再次強調,在
How long (in minutes) to cache metadata before rechecking the remote repository.處
統一設定為
288000 即200天,當然可以設定為更長的時間
設定maven-public
Nexus安裝後內建maven-releases,maven-snapshots兩個倉庫,用於將產生的jar包發布在這兩個倉庫中,在實際開發中需要將maven-releases設定為可以重複發布。
maven-releases
註:maven-snapshots預設是可以重新部署的。
(2) 在maven的安裝路徑下conf/Setting.xml中配置如下內容:
<settings> <pluginGroups> <pluginGroup>org.sonatype.plugins</pluginGroup> </pluginGroups> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/repository/maven-public/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--Enable snapshots for the built in central repo to direct --> <!--all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles> <servers> <server> <id>nexus</id> <username>admin</username> <password>admin123</password> </server> </servers></settings>
(3) 測試
將settings.xml中記錄的maven倉庫地址中的之前下載下來的jar包全部刪除。在maven 工程右鍵 Maven ---> update product,在出來的彈出框中選擇 "force update of snapshorts/releases",重新下載所需依賴的jar包即可。
PS:私服配置的內容參考了:https://www.cnblogs.com/fanzhenyong/p/7709434.html
搭建nexus私服