引言
项目中在更新公共的jar的时候,需要执行命令才能上传到私服上面,重要的时候有的开发人员的环境不能正确的配置maven的环境,不能正确的执行mvn命令,需要找别人来将jar包发布的私服上面,这让我很受不了啊,所以就修改的了项目的pom文件,在idea中直接发布jar包到私服。
1、 在项目的pom文件中,添加下面节点内容,我是在父pom中添加的
<!-- 设置deploy的地址 --> <distributionManagement> <repository> <id>acs-releases</id> <name>acs release resp</name> <url>http://.0.0.0.:8090/repository/maven-releases/</url> </repository> <snapshotRepository> <id>acs-snapshots</id> <name>acs snapshot</name> <url>http://0.0.0.0:8090/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
此节点就在<project>节点中,如果不配置上面内容,会提示下面错误
报错:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project git-demo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
2、我们需要在setting.xml中配置登陆私服的用户名和密码
<servers> <server> <id>acs-releases</id> <username>username</username> <password>pwd</password> </server> <server> <id>acs-snapshots</id> <username>username</username> <password>pwd</password> </server> </servers>
注意:这两部分的配置需要有一个对应,就是这两处的配置的id必须对应,否则会出现没有权限的错误。
错误信息如下:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project *: Failed to deploy artifacts: Could not transfer artifact *:jar:1.0 from/to releases (http://10.1.81.199:8081/nexus/content/repositories/releases/): Failed to transfer file: http://10.1.81.199:8081/nexus/content/repositories/releases/com/cs2c/security-management-client* /1.0/*-1.0.jar. Return code is: 401, ReasonPhrase:Unauthorized.
这样就解决了idea直接发布jar 的问题,不用在每次都是执行命令了。