搭建完成后本地仓库缺少的jar包仍从中央仓库直接下载,可能是没有在setting.xml中添加<mirror>
1.setting.xml
<mirror>
<id>nexus</id>
<name>internal nexus repository</name>
<url>http://localhost:8081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
<!--nexus3.19.1版本,不添加以下内容也可以正常使用,但不添加mirror不能使用-->
<!--配置私服下载jar包的模板-->
<profile>
<!--profile的id-->
<id>dev</id>
<repositories>
<repository>
<id>nexus</id>
<!--仓库地址,即nexus仓库组的地址-->
<url>http://localhost:8081/repository/maven-public/</url>
<!--是否下载releases构件-->
<releases>
<enabled>true</enabled>
</releases>
<!--是否下载snapshots构件-->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
<pluginRepository>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/repository/maven-public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
<!--激活下载模板-->
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
2.添加到要上传项目的pom中确定上传的路径
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<!--不加下面这一段打包上传私服时会报错-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</build>