因工作需要,需要搭建公司自己的私有倉庫,存儲自己的私有jar包,所以研究了下
一、環境准備
1、下載並安裝nexus,然后啟動項目,這部分攻略網上很多,而且基本上都是正確的,此處不做梳理
2、登錄127.0.0.1:8081,默認用戶名密碼是admin/admin123
3、創建私有倉庫
倉庫類型有hosted、proxy、group,hosted-本地存儲。像官方倉庫一樣提供本地私庫功能;proxy-提供代理其它倉庫的類型;group-組類型,能夠組合多個倉庫為一個地址提供服務,所以這里選hosted。
保存后在列表頁面點擊新創建的倉庫,進到詳細頁面,查看倉庫地址並妥善保存,后面會用到
4、創建角色,只擁有新增倉庫的讀取權限。
5、創建擁有該角色的用戶
這樣倉庫就創建好了,接下來是使用,首先是導入jar包,目前只研究了網頁導入
二、私有jar包上傳
1、查找上傳入口
2、選擇jar包並維護信息,如果勾選了Generate a POM file with these coordinates,會自動生成pom文件信息
3、確認jar包,如果按照步驟看到如下信息,表示已經上傳成功
三、本地導出
1、本地maven改造,修改setting文件
首先維護用戶信息,記住此處配置的server.id,后面會用到
<servers> <server> <id>dingxf-third_part</id> <username>dingxf</username> <password>dingxf</password> </server> </servers>
然后配置倉庫信息,首先在<profiles></profiles>中維護以下信息
<profile> <!-- 自定義不重復id --> <id>dingxf</id> <repositories> <repository> <!-- 維護的server.id 如果維護錯誤會報錯:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定義name名,無要求 --> <name>dingxf</name> <!-- 一.3中保存的地址名,如果維護錯誤會報錯:Could not find artifact jar包 in wecredo-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <!-- 維護的server.id 如果維護錯誤會報錯:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定義name名,無要求 --> <name>dingxf</name> <!-- 一.3中保存的地址名,如果維護錯誤會報錯:Could not find artifact jar包 in wecredo-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile>
然后在最外層<settings></settings>中維護以下信息
<activeProfiles> <!-- profile.id 如果不維護或錯誤會報錯:Could not find artifact xxxxx in central (https://repo.maven.apache.org/maven2),此時私有倉庫不起作用 --> <activeProfile>dingxf</activeProfile>
</activeProfiles>
2、然后項目的pom.xml中維護以下信息
<distributionManagement> <repository> <!-- 維護的server.id 如果維護錯誤會報錯:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定義name名,無要求 --> <name>dingxf-third_part</name> <!-- 一.3中保存的地址名,如果維護錯誤會報錯:Could not find artifact jar包 in dingxf-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> </repository> <snapshotRepository> <!-- 維護的server.id 如果維護錯誤會報錯:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定義name名,無要求 --> <name>dingxf-third_part</name> <!-- 一.3中保存的地址名,如果維護錯誤會報錯:Could not find artifact jar包 in dingxf-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> </snapshotRepository> </distributionManagement>