Nexus快速入門、安裝
在公司開發(fā)測試過程中,內(nèi)網(wǎng)團隊使用一個服務(wù)來節(jié)省外網(wǎng)寬帶以及緩存Maven Respository中沒有的jar包
允許上傳和下載私有庫,并且不被外部訪問,安全穩(wěn)定
一、下載
官網(wǎng)下載地址,但是速度很慢,可以使用以下鏈接獲取:添加鏈接描述
二、搭建服務(wù)
- 解壓好下載的nexus壓縮包,會有以下兩個文件:
- 右鍵開始菜單打開管理員cmd,進入到nexus-3.42.0-01\bin目錄下,執(zhí)行: nexus.exe /install nexus 將其安裝到Windows服務(wù)中(因為已經(jīng)安裝過服務(wù),所以再次執(zhí)行會出現(xiàn) “已安裝”的提示)
- 使用nexus.exe /start 或 nexus.exe /stop 進行開啟和關(guān)閉服務(wù)?;蛘邎?zhí)行nexus.exe /run來通過命令窗口方式執(zhí)行。 (第一次啟動會花費較長時間)
- 啟動成功后,默認端口為8081,瀏覽器訪問方式為:localhost:8081。
修改端口可以編輯nexus-3.42.0-01\etc\nexus-default.properties下的application-port屬性
5. 登錄,點擊右上角Sign in進行登錄,默認用戶名是admin,密碼會隨機生成在nexus\sonatype-work\nexus3下的password文件中,登錄后即可修改密碼。
三、配置私服
- 登錄之后菜單欄左側(cè)會有一個設(shè)置的圖標,點擊后再點Repositories進行配置倉庫
- maven-central,maven中央庫,默認從https://repo1.maven.org/maven2/拉取jar (下載速度很慢,這就是下面一步創(chuàng)建阿里云代理的原因);
- maven-releases:私庫打包發(fā)行版jar;(可上傳自編jar包)
- maven-snapshots:私庫快照版jar;(可上傳自編jar包)
-
maven-public:倉庫分組,把上面三個倉庫組合在一起后對外提供服務(wù),在本地maven setting.xml中配置;
- 點擊Create repositories創(chuàng)建一個阿里云代理倉庫 (跟在maven => Setting.xml更改阿里云鏡像道理一樣)
- proxy:提供代理其它倉庫的類型;
- hosted:本地存儲。像官方倉庫一樣提供本地私庫功能;
- group:組類型,能夠組合多個倉庫為一個地址提供服務(wù);
阿里云鏡像服務(wù)URL詳見:倉庫服務(wù)
點擊最下方Create Repositories按鈕創(chuàng)建完畢
- 點擊maven-public 設(shè)置阿里云鏡像優(yōu)先使用
四、在Maven中使用私服
1. 設(shè)置maven conf下的setting.xml文件。
公司的小伙伴需共同將本地的setting.xml指向公司的nexus私有倉
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>E:\maven\mavenLocal</localRepository> <!-- 配置jar包存放位置 -->
<mirrors>
<!-- 配置本地倉庫資源來源 -->
<mirror>
<id>maven-public</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<servers>
<!-- 配置本地倉庫訪問私服的權(quán)限 nexus的 登錄用戶名密碼 -->
<server>
<id>maven-releases</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
<!-- 屬性列表配置 -->
<profiles>
<profile>
<id>my-profile</id>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<!-- 遠程倉庫列表 maven用來填充構(gòu)建系統(tǒng)本地倉庫所使用的一組遠程倉庫 -->
<repositories>
<repository>
<id>maven-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<url>http://localhost:8081/repository/maven-public</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>my-profile</activeProfile>
</activeProfiles>
</settings>
2. 往私有倉上傳maven官方鏡像中下載不到的jar包
文章來源:http://www.zghlxwxcb.cn/news/detail-405430.html
3. 往私有倉發(fā)布自編jar包
- 可使用第二步打包后手動上傳
- 在需發(fā)布的項目pom文件中添加 distributionManagement配置,而后使用 idea 工具右側(cè)的maven欄,點擊 deploy 發(fā)布到遠程倉庫,而后登陸到你的nexus私服即可查看部署的jar包
- package:完成了項目編譯、單元測試、打包功能,但并沒有把打好的可執(zhí)行jar包(war包或其它形式的包)布署到本地maven倉庫和遠程maven私服倉庫
- install: 完成了項目編譯、單元測試、打包功能,同時把打好的可執(zhí)行jar包(war包或其它形式的包)布署到本地maven倉3庫,但沒有布署到遠程maven私服倉庫
- deploy:完成了項目編譯、單元測試、打包功能,同時把打好的可執(zhí)行jar包(war包或其它形式的包)布署到本地maven倉庫和遠程maven私服倉庫
<!-- maven倉庫配置 deploy時可推送到對應(yīng)的配置倉庫中 -->
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus Releases Repository Pro</name>
<url>http://localhost:8081/repository/maven-releases/</url> <!-- 正式版推送到這 -->
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Nexus Snapshots Repository Pro</name>
<url>http://localhost:8081/repository/maven-snapshots/</url> <!-- 測試版推送到這 -->
</snapshotRepository>
</distributionManagement>
文章來源地址http://www.zghlxwxcb.cn/news/detail-405430.html
到了這里,關(guān)于Maven私有倉庫搭建與使用【nexus的配置與使用】【W(wǎng)indows】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!