背景:
內(nèi)網(wǎng)環(huán)境,使用maven構(gòu)建管理項(xiàng)目只能自己搭建鏡像昏兆。nexus3.x需聯(lián)網(wǎng)使用有梆,所以選用nexus2.x來搭建鏡像
環(huán)境:
2瞒御、maven3.5.2
3、windows10
步驟:
- 搭建nexus環(huán)境
1神郊、將下載好的nexus-professional-2.14.10解壓至任意目錄肴裙。
2、打開剛才解壓的目錄涌乳,首先進(jìn)入config目錄蜻懦,修改nexus.properties,修改默認(rèn)端口號(hào)。
#修改端口號(hào)
application-port=12345
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF
# orientdb buffer size in megabytes
storage.diskCache.bufferSize=4096
打開cmd夕晓,進(jìn)入nexus的bin目錄阻肩,執(zhí)行
nexus install
運(yùn)行完成后,會(huì)生成windows服務(wù)运授,可以在windows服務(wù)列表里看到烤惊,默認(rèn)是自動(dòng)啟動(dòng)。
3吁朦、nexus啟動(dòng)后柒室,會(huì)在sonatype-work/nexus/下面生成一批目錄,其中storage/thirdparty目錄就是存放各種依賴的目錄逗宜。
4雄右、將我們外網(wǎng)電腦在maven中下載好的repository復(fù)制到sonatype-work/nexus/storage/thirdparty中,重啟nexus服務(wù)纺讲。本地maven倉庫地址一般會(huì)在C:\Users\your user\.m2\repository
5擂仍、訪問http://127.0.0.1:12345/nexus就能看到內(nèi)網(wǎng)鏡像的倉庫了。其中Repository Path 就是本地的鏡像地址熬甚,后面會(huì)用到逢渔。
-
配置maven
1、修改MAVEN_HOME/config/settings.xml,增加以下節(jié)點(diǎn)
<mirrors>
<mirror>
<id>localRep</id>
<mirrorOf>central</mirrorOf>
<name>the Mirror for neiwang</name>
<url>http://your ip:12345/nexus/content/groups/public/</url>
<!---
這里的地址就是上面的Repository Path
-->
</mirror>
</mirrors>
2乡括、更新IDE的maven配置肃廓,這里以eclipse為例智厌。打開eclipse-window-Preferences-Maven-User Settings,選擇Global Settings盲赊,選擇maven安裝目錄下conf目錄中的settings.xml铣鹏,選擇完畢后,點(diǎn)擊Update Settings 哀蘑。
3诚卸、更新你的maven項(xiàng)目。
結(jié)束:
后續(xù)更新依賴的時(shí)候绘迁,只需把外網(wǎng)的repository復(fù)制到nexus的sonatype-work/nexus/storage/thirdparty中即可惨险。