nexus-2.14.2-01-bundle建構maven私服
一、下載下傳nexus
位址:https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/oss/nexus-2.14.8-01-bundle.zip;
二、解壓nexus-2.14.8-01-bundle.zip到指定的盤符:
三、在bin/jsw下有不同的版本,根據自己的系統選擇正确的版本,這裡選擇window 64位作業系統的版本。
四、啟動服務
介紹:
console-nexus.bat 是以指令視窗的形式啟動,關閉後服務停止
install-nexus.bat 是設定開機啟動,在服務中可以看成到該服務為開機自動啟動(推薦使用這種方式啟動)
stop-nexus.bat 是停止服務
uninstall-nexus.bat 是解除安裝nexus
啟動服務:
看控制台:
五、服務配置
啟動後輸入:http://localhost:8081/nexus
進入在右上角Login登入,初始使用者名:admin 密碼:admin123:
登陸後界面:
1、修改登入密碼:如圖選中admin選項,然後右鍵:
2、配置參數,将Download Remote Indexes 設定為true
3、添加第三方jar包
3.1、選擇和填寫參數(groupId、artifactId、version)都要填寫
3.2、選擇上傳的jar包
六、項目調用方法
1、配置maven的settings.xml檔案
1.1、設定jar包儲存的本地目錄(我設定的是D盤)
<!--設定自己的maven本地倉庫-->
<localRepository>D:/Program Files/maven_repository/repository</localRepository>
1.2、根據私服設定私服位址
<mirrors>
<mirror>
<!--此處配置所有的建構均從私有倉庫中下載下傳 *代表所有,也可以寫central -->
<id>nexus</id>
<name>nexus</name>
<!-- * 表示讓所有倉庫使用該鏡像-->
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
1.3 在setting.xml配置檔案中增加配置:(隻需要修改下圖示注的Releases/Snapshots中對應的位址):
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-rs</id> <!--正式倉庫id-->
<!--name随便-->
<name>Nexus Release Snapshot Repository</name>
<!--位址是nexus中repository(Releases/Snapshots)中對應的位址-->
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<!--位址是nexus中repository(Releases/Snapshots)中對應的位址-->
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<!--插件倉庫位址,各節點的含義和上面是一樣的-->
<pluginRepositories>
<pluginRepository>
<id>nexus-rs</id>
<name>Nexus Release Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活配置-->
<activeProfiles>
<activeProfile>nexus</activeProfile> <!--profile下的id-->
</activeProfiles>
1.4 在eclipse中更換setting.xml檔案:
七、項目測試:
1.1 在eclipse的maven工程的pom.xml檔案中配置:
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
1.2 儲存,如圖可顯示從私服下載下傳jar包:
1.3 可從maven_repository\repository\log4j\log4j 中檢視已經加載了log4j1.2.14版本:
1.4 可從私服中索引log4j:
至此,私服就建立成功了。
八、将本地工程部署建構到Nexus,作為jar/web作為插件:
1、在本地倉庫的setting.xml中配置如下:
<servers>
<server>
<!--這個ID要與下面的repository中的ID一緻-->
<id>releases</id>
<!--nexus中配置的使用者名密碼-->
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
2、在需要建構的項目中修改pom.xml檔案:
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
3、右鍵項目-Run As-Maven build...,執行maven的deploy指令:
4、打開私服:
4.1由于項目pom.xml中設定了<version>0.0.1-RELEASES</version>釋出版本:
是以可以在私服的Releases中檢視到已經部署的項目:
4.2 如果項目pom.xml中設定了<version>0.0.1-SNAPSHOT</version>快照版本:
那麼部署以後可以在私服的Snapshots中檢視到已經部署的項目:
<?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">
<!-- 插件組 -->
<pluginGroups>
</pluginGroups>
<!-- 代理組 -->
<proxies>
</proxies>
<servers>
<server>
<!--這個ID要與下面的repository中的ID一緻-->
<id>releases</id>
<!--nexus中配置的使用者名密碼-->
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<!--設定自己的maven本地倉庫-->
<localRepository>D:/Program Files/maven_repository/repository</localRepository>
<mirrors>
<mirror>
<!--此處配置所有的建構均從私有倉庫中下載下傳 *代表所有,也可以寫central -->
<id>nexus</id>
<name>nexus</name>
<!-- * 表示讓所有倉庫使用該鏡像-->
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-rs</id> <!--正式倉庫id-->
<!--name随便-->
<name>Nexus Release Snapshot Repository</name>
<!--位址是nexus中repository(Releases/Snapshots)中對應的位址-->
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<!--位址是nexus中repository(Releases/Snapshots)中對應的位址-->
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<!--插件倉庫位址,各節點的含義和上面是一樣的-->
<pluginRepositories>
<pluginRepository>
<id>nexus-rs</id>
<name>Nexus Release Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活配置-->
<activeProfiles>
<activeProfile>nexus</activeProfile> <!--profile下的id-->
</activeProfiles>