将maven项目发布到私服

1、局域网私服

   首先保证已经安装配置好了局域网的私服(具体私服的搭建可以查看相关资料)

   私服页面访问地址:http://192.168.0.110:8081/nexus,使用admin登录,默认的用户名和密码是:admin/admin123

2、项目的仓库部署配置

   1)pom文件中插件配置

 1 <build>
 2     <pluginManagement>
 3         <plugins>
 4             <plugin>
 5                 <groupId>org.apache.maven.plugins</groupId>
 6                 <artifactId>maven-deploy-plugin</artifactId>
 7                 <version>2.8.2</version>
 8             </plugin>
 9         </plugins>
10     </pluginManagement>
11 </build>
1 <build>
2     <plugins>
3         <plugin>
4             <groupId>org.apache.maven.plugins</groupId>
5             <artifactId>maven-deploy-plugin</artifactId>
6             <version>2.8.2</version>
7         </plugin>
8     </plugins>
9 </build>

   2)pom文件中私服仓库配置

 1 <distributionManagement>
 2         <repository>
 3             <id>thirdparty</id>
 4             <url>http://192.168.0.110:8081/nexus/content/repositories/thirdparty/</url>
 5         </repository>
 6         <snapshotRepository>
 7             <id>nexus-snapshots</id>
 8             <url>http://192.168.0.110:8081/nexus/content/repositories/snapshots/</url>
 9         </snapshotRepository>
10 </distributionManagement>

   Release版本和Snapshot版本对应的仓库URL,可以在私服的web页面上查看(本文的Release版本都发布到3rd party仓库下面)

   View/Repositories -> Repositories -> Repositories Path

3、Maven的settings配置文件

   1)配置Servers(项目pom文件中<distributionManagement>标签里面的id要与这里面的id保持一致)

 1 <servers>
 2     <server>
 3         <id>nexus-releases</id>
 4         <username>admin</username>
 5         <password>admin123</password>
 6     </server>
 7     <server>
 8         <id>nexus-snapshots</id>
 9         <username>admin</username>
10         <password>admin123</password>
11     </server>
12     <server>
13         <id>thirdparty</id>
14         <username>admin</username>
15         <password>admin123</password>
16     </server>
17 </servers>

   2)配置Mirror镜像,配置指向私服

1 <mirrors>
2     <mirror>
3         <id>nexus</id>
4         <name>internal nexus repository</name>
5         <url>http://192.168.0.110:8081/nexus/content/groups/public/</url>
6         <mirrorOf>*</mirrorOf>
7     </mirror>
8 </mirrors>

   3)配置仓库描述

 1 <profile>
 2     <id>dev</id>
 3     <repositories>
 4         <repository>
 5             <id>nexus-releases</id>
 6             <url>http://192.168.0.110:8081/nexus/content/repositories/releases/</url>
 7             <releases><enabled>true</enabled></releases>
 8             <snapshots><enabled>true</enabled></snapshots>
 9         </repository>
10         <repository>
11             <id>nexus-snapshots</id>
12             <url>http://192.168.0.110:8081/nexus/content/repositories/snapshots/</url>
13             <releases><enabled>true</enabled></releases>
14             <snapshots><enabled>true</enabled></snapshots>
15         </repository>
16         <repository>
17             <id>central</id>
18             <name>Central</name>
19             <url>http://192.168.0.110:8081/nexus/content/repositories/central/</url>
20             <releases><enabled>true</enabled></releases>
21             <snapshots><enabled>true</enabled></snapshots>
22         </repository>    
23         <repository>
24             <id>thirdparty</id>
25             <url>http://192.168.0.110:8081/nexus/content/repositories/thirdparty/</url>
26             <releases><enabled>true</enabled></releases>
27             <snapshots><enabled>true</enabled></snapshots>
28         </repository>
29     </repositories>
30 </profile>

4、工程项目发布

   1)执行发布命令

   mvn  clean  deploy

   2)发布成功之后,可以在页面上查看到刚刚发布的jar包

   View/Repositories -> Repositories -> 3rd party -> Browse Index

原文地址:https://www.cnblogs.com/lianliang/p/8109501.html