1、在setting.xml文件中增加用户名和密码配置(特别注意这里的ID)
<servers>
<server>
<id>maven-repository-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-repository-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
2、在项目的pom.xml中增加以下内容
<build>
<plugins>
<!-- 要将源码放上去,需要加入这个插件 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<!-- 这里的ID要和setting的id一致-->
<id>maven-repository-releases</id>
<url>http://maven私服的IP:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<!-- 这里的ID要和setting的id一致-->
<id>maven-repository-snapshots</id>
<url>http://maven私服的IP:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
3、如下图运行项目即可