國內訪問maven倉庫速度渣渣,公司訪問外網速度不快,即便用阿里雲鏡像效果也不佳。在局域網內搭建Maven私服,除了能從私服加速下載jar包,還能將內部通用模塊發佈在私服上供其餘同事使用。對內部項目部署頗有幫助。html
下載nexus-2.14.2-01-bundle.tar.gz
https://www.sonatype.com/download-oss-sonatype瀏覽器
# 添加用戶 adduser nexus passwd nexus su nexus cd /home mkdir nexus cd nexus tar xvzf nexus-2.14.2-01-bundle.tar.gz cd nexus-2.14.2-01/bin #啓動nexus ./nexus start
瀏覽器中輸入http://127.0.0.1:8081/nexus/maven
新搭建的neuxs環境只是一個空的倉庫,須要手動和遠程中心庫進行同步,nexus默認是關閉遠程索引下載,最重要的一件事情就是開啓遠程索引下載。登錄nexus系統,默認用戶名密碼爲admin/admin123阿里雲
這樣設置之後, Nexus會自動從遠程中央倉庫下載索引文件, 爲了檢驗索引文件自動下載是否生效,能夠卻換到Browse Index查看url
Repositories –> Add –>ProxyRepository 阿里的maven鏡像: http://maven.aliyun.com/nexus/content/groups/public/ Checksum Policy 能夠改成ignore
Repositories –> Public Repositories
將右側欄所有加入左側欄便可 spa
修改maven的settings.xml配置文件,如C:\Users\xieyue.m2\settings.xml.net
<!--deploy發佈項目到私服的用戶密碼--> <servers> <server> <id>releases</id> <username>deployment</username> <password>xxx</password> </server> <server> <id>snapshots</id> <username>deployment</username> <password>xxx</password> </server> </servers> <!--使用私服倉庫--> <profiles> <profile> <repositories> <repository> <id>nexus</id> <name>nexus</name> <url>http://132.97.8.177:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
<!-- mvn deploy的發佈地址 --> <distributionManagement> <repository> <id>releases</id> <name>Internal Releases</name> <url>http://132.97.8.177:8081/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Internal Snapshots</name> <url>http://132.97.8.177:8081/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> <!-- 使用本地maven私庫 --> <repositories> <repository> <id>nexus</id> <name>nexus</name> <url>http://132.97.8.177:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
http://books.sonatype.com/nexus-book/reference/installing.html http://blog.csdn.net/ClementAD/article/details/52670968