一、下载与安装
二、Maven配置
打开Maven配置文件 settings.xml
1、在servers节点中添加两个节点,releases 和 snapshots
<server>
<id>nexus-releases</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>username</username>
<password>password</password>
</server>
2、在mirrors节点添加
<mirror>
<id>nexus-releases</id> <!-- 对应server节点的id -->
<url>http://192.168.1.2:8081/repository/maven-public/</url><!-- 私服仓库地址 -->
<mirrorOf>*</mirrorOf>
</mirror>
3、在profiles节点添加
<profile>
<id>nexus-releases</id>
<repositories>
<repository>
<id>central</id>
<url>http://192.168.1.2:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://192.168.1.2:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
4、在activeProfiles节点添加
<activeProfile>nexus-releases</activeProfile>
通过以上配置,已经完成了私服的配置
完整的settings.xml 配置文件
<?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>F:/maven/repository-ali</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>nexus-releases</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>username</username>
<password>password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-releases</id>
<url>http://192.168.1.2:8081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus-releases</id>
<repositories>
<repository>
<id>central</id>
<url>http://192.168.1.2:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://192.168.1.2:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus-releases</activeProfile>
</activeProfiles>
</settings>
三、使用 idea 发布本地jar包到私服
1、在pom.xml文件的project节点里面添加以下代码
<!-- 设置deploy的地址 -->
<distributionManagement>
<repository>
<id>nexus-releases</id><!-- 对应server节点的id -->
<name>Nexus Release Repository</name>
<url>http://192.168.1.2:8081/repository/maven-releases/</url><!-- 对应私服的 maven-releases 仓库-->
</repository>
<snapshotRepository>
<id>nexus-snapshots</id><!-- 对应server节点的id -->
<name>Nexus Snapshot Repository</name>
<url>http://192.168.1.2:8081/repository/maven-snapshots/</url><!-- 对应私服的 maven-snapshots 仓库-->
</snapshotRepository>
</distributionManagement>
2、打开 idea 开发工具在右侧点开Maven Project 选择要上传的项目点击deploy。
点击
控制台输出BUILD SUCCESS则成功
在私服中可以看到包已经上传
网友评论