maven配置
1.根據nexus配置按需增加身份驗證
<servers> <server> <id>nexus</id> <username>admin</username> <password>123456</password> </server> </servers>
2.配置倉庫地址
<mirrors> <mirror> <id>central</id> <name>central-mirror</name> <url>http://localhost:8081/repository/nexus-zl/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors>
開始搭建nexus
1.下載nexus
https://www.sonatype.com/?hsLang=en-us
2.解壓安裝包
3.進入D:\work\nexus\nexus-3.37.3-02\bin,打開cmd執行以下命令
安裝到服務
nexus.exe/install
立即啟動
nexus.exe/run
4.啟動成功打開地址localhost:8081進入頁面
nexus默認提供了2個賬號admin(管理員)和anonymous(訪客),舊版本可能默認密碼admin123,新版本首次登錄admin的密碼保存在./sonatype-work/nexus3/文件夾下,首次登錄頁面也會有這一方面的引導
nexus創建倉庫
1.進入管理頁面,並使用admin登錄
2.點擊頂部齒輪(Server administration and configuration)后進入左側repositories,點擊create repository創建倉庫
3.選擇maven2(hosted)
4.輸入倉庫名其余默認,點擊創建倉庫即可
nexus批量安裝jar包
1.創建文件mavenimport.sh,內容如下
#!/bin/bash # copy and run this script to the root of the repository directory containing files # this script attempts to exclude uploading itself explicitly so the script name is important # Get command line params while getopts ":r:u:p:" opt; do case $opt in r) REPO_URL="$OPTARG" ;; u) USERNAME="$OPTARG" ;; p) PASSWORD="$OPTARG" ;; esac done find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
2.將命令文件放入jar包根目錄
如jar包存放根路徑為E:\maven\repository下有兩個jar,則應放在E:\maven\repository下和com、cn目錄同級
E:\maven\repository\com\alibaba\druid\1.2.8
E:\maven\repository\cn\hutool\hutool-all\5.7.18
3.執行命令
linux下先chmod +x mavenimport.sh
windows下使用git bash執行
./mavenimport.sh -u admin -p 123456 -r http://localhost:8081/repository/nexus-zl/
其中紅色部分為你創建的倉庫名
賬號密碼是nexus admin的賬號密碼
4.等待命令執行成功即可,速度不快
可能出現的問題
1.nexus頁面彈出提示:提示一個錯誤,磁盤空間不足
修改D:\work\nexus\nexus-3.37.3-02\bin下nexus.vmoptions
-Dstorage.diskCache.diskFreeSpaceLimit=2048