一、安裝nexus3
https://blog.csdn.net/u010375456/article/details/95041237
二、maven倉庫介紹
A、maven-central:這是maven的中心倉庫,nexus這裏只是做一個代理,最後會轉發到maven的central庫
B、maven-public:這是一個倉庫組,訪問這個倉庫組的地址其實會訪問組內所有倉庫
C、maven-releases:這是nexus提供的一個默認的存放release版本jar包的倉庫
D、maven-snapshots:這是nexus提供的一個默認的存放snapshot版本jar包的倉庫
三、上傳jar包
1、上傳jar需要認證,在maven的settings.xml文件中配置。
這裏配置兩個用戶,一個部署release類型jar包的,一個是部署snapshot類型jar包的,密碼根據自己實際情況配置。
id用於唯一指定一條認證配信息,之後會在pom中使用。
2、接着新建一個quick-start的maven項目,在pom中配置distributionManagement標籤,該標籤負責描述maven deploy上傳遠程倉庫
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jhtech</groupId>
<artifactId>mavenTest</artifactId>
<version>1.0-SNAPSHOT</version>
<name>mavenTest</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<distributionManagement>
<repository>
<id>release_user</id>
<name>Release Deploy</name>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshot_user</id>
<name>Snapshot Deploy</name>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
這裏配置了上傳的url,具體的url可以在nexus的倉庫瀏覽界面下點擊倉庫的url copy獲得。使用剛纔的兩個認證信息,把jar包存在nexus提供的默認倉庫下。id對應了setting.xml裏配置的信息,name隨意。
3、項目中執行,部署jar到nexus上
mvn clean deploy
4、nexus服務器顯示對應的jar
四、拉取jar包
1、新建一個maven的quick-start項目,然後需要在pom中加入依賴,並且配置我們的nexus倉庫
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jhtech</groupId>
<artifactId>mavenTest2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>mavenTest2</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.jhtech</groupId>
<artifactId>mavenTest</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>nexus-public</id>
<name>Nexus Public</name>
<url>http://localhost:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
2、執行命令
mvn clean package
3、本地項目已經有對應jar包