1、下載maven私服工具
可以百度搜索 或 從百度網盤中下載
這裏已經將工具上傳到百度網盤,下載鏈接:
鏈接:https://pan.baidu.com/s/1eSh_TegWUFsEBlv92PWYiw
提取碼:cobz
下載 windows系統安裝包,即 nexus-2.12.0-01-bundle.zip 文件
2、安裝私服
首先,先將 nexus-2.12.0-01-bundle.zip 文件解壓到某個目錄(目錄不含空格)
解壓後發現有兩個目錄,分別是:nexus-2.12.0-01 和 sonatype-work
nexus-2.12.0-01 目錄:私服安裝及運行時需要用到相關文件
私服倉庫:在 sonatype-work\nexus 目錄下面,由於還沒有創建倉庫,所以該目錄下面沒有任何目錄或文件。
安裝私服:將 私服安裝到 windows 服務項中
使用 windows 命令行(以管理員身份運行),進入到 nexus-2.12.0-01\bin 目錄,執行 nexus.bat install 安裝私服
此時windows服務項中,可以找到服務名 爲 nexus 的服務。說明私服安裝成功。
3、啓動私服服務器
注意私服服務器端口占用問題:服務器默認使用的是 8081 端口。(在 nexus-2.12.0-01\conf\nexus.properties 文件中可以看到相關信息 )
在 windows 服務項中,找到服務名 爲 nexus 的服務,並啓動該服務。
點擊 “啓動” 服務。
或者服務項中,右鍵啓動。
私服服務器啓動成功:
4、訪問私服服務器(默認端口爲 8081)
打開電腦中的瀏覽器:
輸入地址 http://localhost:8081/nexus/ 或者 http://192.168.1.106:8081/nexus/
瀏覽器自動跳轉到 http://localhost:8081/nexus/#welcome 或者 http://192.168.1.106:8081/nexus/#welcome
這裏以localhost地址爲例:
登錄服務器:默認賬號及密碼爲 admin / admin123
登錄成功:右上角會顯示登錄賬號信息、左側菜單可看到 Views/Repositories 選項。
5、查看倉庫
左側菜單可看到 Views/Repositories 選項, 點擊 Repositories 查看倉庫。
在私服安裝目錄 sonatype-work\nexus\storage 目錄下,可以找到對應的倉庫目錄
6、上傳 jar 包到私服
- 配置maven環境,修改 settings 文件,配置連接私服的用戶名和密碼
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
releases 連接發佈版本項目倉庫
snapshots 連接測試版本項目倉庫
- 配置 (工程或模塊的)pom.xml 文件
配置私服倉庫的地址,本公司的自己的 jar 包會上傳到私服的宿主倉庫,如果工程的版本爲 release 則上傳到私服的 release 倉庫,如果版本爲 snapshot 則上傳到私服的 snapshot 倉庫,這裏演示配置成localhost即可,如果是是公司中安裝的私服地址應該是localhost替換成私服ip地址
在工程或模塊的 pom.xml 文件中,添加如下代碼:
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
- 測試
- 配置maven環境,修改 settings 文件,配置配置私服的倉庫
<profile>
<!--profile 的 id-->
<id>dev</id>
<repositories>
<repository>
<!--倉庫 id,repositories 可以配置多個倉庫,保證 id 不重複-->
<id>nexus</id>
<!--倉庫地址,即 nexus 倉庫組的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!--是否下載 releases 構件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下載 snapshots 構件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件倉庫,maven 的運行依賴插件,也需要從私服下載插件 -->
<pluginRepository>
<!-- 插件倉庫的 id 不允許重複,如果重複後邊配置會覆蓋前邊 -->
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
-
測試從私服下載 jar 包