Maven精选系列--私库搭建及使用
轉(zhuǎn)載自?Maven精選系列--私庫搭建及使用
為什么要使用私庫
maven默認(rèn)去遠(yuǎn)程中央倉庫下載JAR包的,訪問國外網(wǎng)絡(luò)相當(dāng)慢,如果團(tuán)隊(duì)每個人都去下載一遍無疑是網(wǎng)絡(luò)的浪費(fèi),當(dāng)然也可以添加國內(nèi)的鏡像,如阿里的比較穩(wěn)定,但如果想添加遠(yuǎn)程不存在的像第三方公司的JAR包就比較麻煩。
所以,使用私庫,第一,開源包只要有一個人下載過其他人就不需要再下載了,直接從私庫下載即可。第二,可以用來管理第三方公司的或者遠(yuǎn)程倉庫不存在的JAR包,或者公司不開源的JAR包。
推薦國內(nèi)穩(wěn)定的鏡像,如阿里的
http://maven.aliyun.com/nexus/content/groups/public/
nexus下載安裝
首先去sonatype官網(wǎng)下載nexus包,要下載開源免費(fèi)版的OSS版,即Open Source Software。
https://www.sonatype.com/nexus-repository-oss
下載最新的3.X的版本,這里以windows為例進(jìn)行下載。
下載后點(diǎn)擊bin目錄中的啟動文件即可,默認(rèn)的端口是8081,訪問路徑是/,也可以去配置文件中修改,這里以默認(rèn)。
啟動后,打開localhost:8081,nexus默認(rèn)的用戶名是admin/admin123
默認(rèn)安裝有以下這幾個倉庫,在控制臺也可以修改遠(yuǎn)程倉庫的地址,第三方倉庫等。
Maven配置
修改maven主目錄conf/setting.xml配置文件。
添加nexus認(rèn)證的用戶名和密碼配置信息。
<servers>
????<server>
????? ? ? <id>nexus-releases</id>
????? ? ? <privateKey>admin</privateKey>
????? ? ? <passphrase>admin123</passphrase>
????</server>
????<server>
????? ? ? <id>nexus-snapshots</id>
????? ? ? <privateKey>admin</privateKey>
????? ? ? <passphrase>admin123</passphrase>
????</server>
</servers>
添加mirror鏡像
?<mirrors>
????<mirror>
????? ? ? <id>Nexus</id>
????? ? ? <mirrorOf>*</mirrorOf>
????? ? ? <name>Nexus</name>
????? ? ? <url>http://127.0.0.1:8081/repository/maven-public/</url>
?????</mirror>
? </mirrors>
添加私庫
<profiles>
<profile>
<id>Nexus</id>
<repositories>
<repository>
<id>Nexus</id>
<name>Nexus</name>
<url>http://127.0.0.1:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>Nexus</id>
<name>Nexus</name>
<url>http://127.0.0.1:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
??
激活私庫
<activeProfiles>
???? <activeProfile>Nexus</activeProfile>
</activeProfiles>
發(fā)布到私庫
在pom配置文件中添加
<!-- nexus-releases nexus-snapshots與settings.xml中server下的id對應(yīng) -->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Releases Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshots Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
在項(xiàng)目上使用命令mvn deploy打包就能發(fā)布到私庫。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎
總結(jié)
以上是生活随笔為你收集整理的Maven精选系列--私库搭建及使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联想一体机电脑卡顿严重解决方法?
- 下一篇: 联想T40笔记本配置?