maven上传jar包到nexus私有仓库

maven发布jar包到nexus私有仓库的配置方法。

pom.xml

<distributionManagement>
		<snapshotRepository>
			<id>snapshots</id>
			<url>http://39.100.107.17:8081/repository/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-deploy-plugin</artifactId>
				<version>2.7</version>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.sonatype.plugins</groupId>
				<artifactId>nexus-staging-maven-plugin</artifactId>
				<version>1.6.8</version>
				<executions>
					<execution>
						<id>default-deploy</id>
						<phase>deploy</phase>
						<goals>
							<goal>deploy</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<serverId>nexus</serverId>
					<nexusUrl>http://39.100.107.17:8081/nexus/</nexusUrl>
					<skipStaging>true</skipStaging>
				</configuration>
			</plugin>
		</plugins>
	</build>

settings.xml

</servers>
....
<server>
   <id>snapshots</id>
   <username>admin</username>
   <password>admin123</password>
  </server>
... 
</servers>

打包上传到nexus:

mvn clean deploy -Dmaven.test.skip=true

说明:mvn命令打包默认使用当前用户下的settings.xml配置,以windows为例:

C:\Users\nick\.m2\settings.xml

 注:如果目录下不存在该文件,从maven安装目录下copy一份,并正确配置,否则可能导致上传失败,如:401错误。