Eclipse中执行Maven deploy报401错误

Error 401 of Maven Deploy in Eclipse

错误现象

用Eclipse向Maven私服上传jar包时,报了一个401错误,ERROR输出如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project XXXXXXXX: Failed to deploy artifacts: Could not transfer artifact XXXXXXXX: Access denied to XXXXXXXX. Error code 401, 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

第一行展示了错误的详细内容,可以看到出错的原因是:

Access denied to XXXXXXXX. Error code 401, Unauthorized

解决办法

错误的原因是我们无权访问服务器,我们首先排查Maven配置文件setting.xml中的username和password是否配置正确(用户名及密码应以私服实际配置为准):

<servers> <server> <id>nexus-releases</id> <username>admin</username><!-- 私服的releases仓库用户名,默认是admin --> <password>admin123</password><!-- 对应的密码,默认是admin123 --> </server> <server> <id>nexus-snapshots</id> <username>admin</username><!-- 私服的snapshots仓库用户名,默认是admin --> <password>admin123</password><!-- 对应的密码,默认是admin123 --> </server> </servers>

上面的配置无误的话,再在Eclipse中排查项目的pom.xml文件中Maven仓库是否配置正确:

<distributionManagement> <repository> <id>nexus-releases</id><!-- 此处的id必须与setting.xml中的id一致 --> <name>Nexus Releases Repository</name> <url>XXXXXXXX</url><!-- 私服的releases仓库地址 --> </repository> <snapshotRepository> <id>nexus-snapshots</id><!-- 此处的id必须与setting.xml中的id一致 --> <name>Nexus Snapshots Repository</name> <url>XXXXXXXX</url><!-- 私服的snapshots仓库地址 --> </snapshotRepository> </distributionManagement>

如果上述两项配置都没有问题的话,还需要在Eclipse中检查执行Maven deploy命令所用的Maven Runtime是否正确。在项目上右键打开运行配置:

打开项目的运行配置

在右侧的配置中看我们执行deploy时用的Maven Runtime,如果是EMBEDDED即内嵌Maven的话,就需要切换成我们安装的外部Maven:

查看或修改Maven Runtime

切换之后,点击Apply保存配置,然后重新上传jar包即可。

 

文章评论
${fromAuthor ? '郄正元' : '游客'} 作者 ${gmtCreate}
${content}
${subList.length}
发表评论
${commentToArticle ? '' : parentContent}
字数:0/${maxCommentLength}
该邮箱地址仅用于接收其他用户的回复提醒,不会泄露