使用nexus搭建的私仓,将jar上传到3rdParty时报错,如何解决?

mvn deploy:deploy-file -DgroupId=chinapay -DartifactId=chinapayfilesecure -Dversion=1.0 -Dpackaging=jar -Dfile=E:\repo\repository1\chinapay\chinapayfilesecure\1.0\chinapayfilesecure-1.0.jar -Durl=http://localhost:8081/repository/3rdParty/ -DrepositoryId=3rdParty
E:\repo\repository1\chinapay\chinapaysecure\1.0>mvn deploy:deploy-file -DgroupId=chinapay -DartifactId=chinapayfilesecure -Dversion=1.0 -Dpackaging=jar -Dfile=E:\repo\repository1\chinapay\chinapayfilesecure\1.0\chinapayfilesecure-1.0.jar -Durl=http://localhost:8081/repository/3rdParty/ -DrepositoryId=3rdParty
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom ---
Uploading: http://localhost:8081/repository/3rdParty/chinapay/chinapayfilesecure/1.0/chinapayfilesecure-1.0.jar
Uploading: http://localhost:8081/repository/3rdParty/chinapay/chinapayfilesecure/1.0/chinapayfilesecure-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.685 s
[INFO] Finished at: 2017-07-17T17:42:30+08:00
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact chinapay:chinapayfilesecure:jar:1.0 from/to 3rdParty (http://localhost:8081/repository/3rdParty/): Failed to transfer file: http://localhost:8081/repository/3rdParty/chinapay/chinapayfilesecure/1.0/chinapayfilesecure-1.0.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

E:\repo\repository1\chinapay\chinapaysecure\1.0>
阅读 6.4k
2 个回答

已经解决,只要在maven的配置文件里面添加 这一行就可以了。

 <server>  
            <id>3rdParty</id>  
            <username>admin</username>  
            <password>admin123</password>  
        </server> 
1.没有配置私服Neuxs 用户信息,或者配置错误
用户配置

~/.m2/settings.xml

私服Neuxs 用户信息配置

/Users/*/apache-maven-3.3.9/conf/settings.xml

两者都要配置,且要保持一致。

     <server>
        <id>nexus-releases</id>
        <username>admin</username>
        <password>abc123_</password>
    </server>

    <server>
        <id>nexus-snapshots</id>
        <username>admin</username>
        <password>abc123_</password>
    </server>

配置完记得重启nexus

2.id不一致导致

pom.xml 文件中的<distributionManagement>.<repository>.<id> 和 settings.xml 文件中的<server>.<id>的属性值不一致导致的认证错误。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题