Java 为什么我在 Maven 中收到“401 Unauthorized”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24830610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why am I getting a "401 Unauthorized" error in Maven?
提问by aliteralmind
Why am I getting a "401 Unauthorized" error in Maven?
为什么我在 Maven 中收到“401 Unauthorized”错误?
Here's the error I'm getting when calling mvn deploy
(full logs at the bottom):
这是我在调用时遇到的错误mvn deploy
(底部的完整日志):
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
According to this sonatype support page:
根据这个sonatype 支持页面:
"If you are receiving a 401 it is because maven is sending the wrong login credentials, or no credentials at all."
“如果您收到 401,那是因为 maven 发送了错误的登录凭据,或者根本没有凭据。”
Below are the steps I've taken, below that are my full settings.xml
and pom.xml
files, and below that are the full logs from mvn deploy
and mvn deploy -e
.
下面是我采取的步骤,下面是我的完整settings.xml
和pom.xml
文件,下面是来自mvn deploy
和的完整日志mvn deploy -e
。
Any ideas would be appreciated. I am just hitting wall after wall with Maven.
任何想法,将不胜感激。我只是和 Maven 一起撞墙。
I followed sonatype's checklistwhen receiving a 401 error:
收到 401 错误时,我遵循了sonatype 的清单:
Checklist item 1. Make sure your username/password is correct by logging into the Nexus UI. If curl is installed on your machine, you can try deploying an artifact with...
检查清单项目 1。登录 Nexus UI,确保您的用户名/密码正确。如果您的机器上安装了 curl,您可以尝试使用...
- I successfully logged in and out of the sonatype.org website, using the user/pass in
settings.xml
. - I attemptedto use
curl
to manually deploy an artifact, with the command
- 我使用 user/pass in 成功登录和退出了 sonatype.org 网站
settings.xml
。 - 我尝试使用
curl
以下命令手动部署工件
[C:\]curl -u MY_SONATYPE_DOT_COM_USERNAME:MY_SONATYPE_DOT_COM_PASSWORD https://oss.sonatype.org/content/repositories/snapshots/com/github/aliteralmind/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.224928-1.pom --request PUT --data @pom.xml
[C:\]curl -u MY_SONATYPE_DOT_COM_USERNAME:MY_SONATYPE_DOT_COM_PASSWORD https://oss.sonatype.org/content/repositories/snapshots/com/github/aliteralmind/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.224928-1.pom --request PUT --data @pom.xml
but got this error:
但得到这个错误:
Warning: Couldn't read data from file "pom.xml", this makes an empty POST.
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
I ran it again with the -k
option, and this time got only this:
我用这个-k
选项再次运行它,这次只得到了这个:
Couldn't read data from file "pom.xml", this makes an empty POST.
I've never used curl before, so I'm at a loss on what to do with this information.
我以前从未使用过 curl,所以我不知道如何处理这些信息。
Checklist item 2. If there is no error output, ensure your user privileges are correctly configured on the server. Make sure to drop the repo you just created.
清单项目 2。如果没有错误输出,请确保您的用户权限在服务器上正确配置。确保删除您刚刚创建的存储库。
I don't know what "drop" means. I believe my privileges are properly installed, as I received this message from sonatype:
我不知道“下降”是什么意思。我相信我的权限已正确安装,因为我收到了来自 sonatype 的消息:
- Configuration has been prepared, now you can:
- Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots
- Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2
- Promote staged artifacts into repository 'Releases'
- Download snapshot and release artifacts from group https://oss.sonatype.org/content/groups/public
- Download snapshot, release and staged artifacts from staging group https://oss.sonatype.org/content/groups/staging
- 配置已经准备好,现在您可以:
- 将快照工件部署到存储库https://oss.sonatype.org/content/repositories/snapshots
- 将发布工件部署到暂存库https://oss.sonatype.org/service/local/staging/deploy/maven2
- 将分阶段的工件提升到存储库“发布”中
- 从组https://oss.sonatype.org/content/groups/public下载快照和发布工件
- 从暂存组下载快照、发布和暂存工件https://oss.sonatype.org/content/groups/staging
and I havesuccessfully put these itemsonto the server via mvn deploy
in the past couple days.
在过去的几天里,我已经成功地将这些项目放到了服务器上mvn deploy
。
The project's settings:
项目的设置:
Checklist item 3. Make sure you have configured a server in
settings.xml
and that the server id is identical to the distribution repository id in pom.xml.
检查清单第 3 项。确保您已在其中配置了服务器,
settings.xml
并且服务器 ID 与 pom.xml 中的分发存储库 ID 相同。
- In
settings.xml
, settings/servers/server/id equalsossrh
- In
pom.xml
, distributionManagement/snapshotRepository/id equalsossrh
- 在
settings.xml
, settings/servers/server/id 等于ossrh
- 在
pom.xml
,distributionManagement/snapshotRepository/id 等于ossrh
(full files are at the bottom)
(完整文件在底部)
Checklist item 4. Make sure your settings.xml is in the correct place (normally it's _~/.m2/settings.xml). You can check this by running mvn help:effective-settings.
清单项目 4。确保您的 settings.xml 位于正确的位置(通常是 _~/.m2/settings.xml)。您可以通过运行 mvn help:effective-settings 来检查这一点。
According to Maven's settings reference, settings.xml must be in one of two locations:
根据 Maven 的设置参考,settings.xml 必须位于以下两个位置之一:
- The Maven install:
$M2_HOME/conf/settings.xml
- A user's install:
${user.home}/.m2/settings.xml
- Maven 安装:
$M2_HOME/conf/settings.xml
- 用户安装:
${user.home}/.m2/settings.xml
Here's my setup:
这是我的设置:
settings.xml
:C:\applications\programming\apache-maven-3.2.2\conf\settings.xml
M2_HOME
isC:\applications\programming\apache-maven-3.2.2
settings.xml
:C:\applications\programming\apache-maven-3.2.2\conf\settings.xml
M2_HOME
是C:\applications\programming\apache-maven-3.2.2
Output for mvn help:effective-settings
:
输出mvn help:effective-settings
:
[C:\applications\utilities\curl]
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:effective-settings (default-cli) @ standalone-pom ---
[INFO]
Effective user-specific configuration settings:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!-- -->
<!-- Generated by Maven Help Plugin on 2014-07-18T12:48:19 -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
<!-- -->
<!-- ====================================================================== -->
<!-- ====================================================================== -->
<!-- -->
<!-- Effective Settings for 'jeffy' on 'kermit-the-frog' -->
<!-- -->
<!-- ====================================================================== -->
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sc
hemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">C:\Users\jeffy\.m2\repository</localRepository
>
<servers xmlns="http://maven.apache.org/SETTINGS/1.1.0">
<server>
<username>MY_SONATYPE_DOT_COM_USERNAME</username>
<password>***</password>
<id>ossrh</id>
</server>
</servers>
<pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
<pluginGroup>org.apache.maven.plugins</pluginGroup>
<pluginGroup>org.codehaus.mojo</pluginGroup>
</pluginGroups>
</settings>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.310 s
[INFO] Finished at: 2014-07-18T12:48:19-04:00
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
Checklist item 5. If the server is using https but the URL in your POM is http, you might get 401 as well.
检查清单项目 5。如果服务器使用 https 但 POM 中的 URL 是 http,您也可能会收到 401。
I don't understand which url it's referring to.
我不明白它指的是哪个网址。
Checklist item 6. Use the latest version of Maven, as there is a known issue regarding 401: MNG-4469
清单项目 6。使用最新版本的 Maven,因为 401 存在一个已知问题:MNG-4469
I am using the latest version:
我正在使用最新版本:
[C:\]mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T09:51:42-04:00)
Maven home: C:\applications\programming\apache-maven-3.2.2
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: C:\applications\programming\jdk_7_51\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
------------------
------------------
Full settings.xml
and pom.xml
files
完整settings.xml
和pom.xml
文件
(Full logs for mvn deploy
and mvn deploy -e
below)
(完整日志mvn deploy
及mvn deploy -e
以下)
settings.xml
:
settings.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>ossrh</id>
<username>MY_SONATYPE_DOT_COM_USERNAME</username>
<password>MY_SONATYPE_DOT_COM_PASSWORD</password>
</server>
</servers>
<pluginGroups></pluginGroups>
<proxies></proxies>
<mirrors></mirrors>
<profiles></profiles>
</settings>
pom.xml:
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.aliteralmind</groupId>
<artifactId>xbnjava</artifactId>
<packaging>pom</packaging>
<version>0.1.2</version>
<name>XBN-Java</name>
<url>https://github.com/aliteralmind/xbnjava</url>
<inceptionYear>2014</inceptionYear>
<organization>
<name>Jeff Epstein</name>
</organization>
<description>XBN-Java is a collection of generically-useful backend (server side, non-GUI) programming utilities, featuring RegexReplacer and FilteredLineIterator. XBN-Java is the foundation of Codelet (http://codelet.aliteralmind.com).</description>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<licenses>
<license>
<name>Lesser General Public License (LGPL) version 3.0</name>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
<license>
<name>Apache Software License (ASL) version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>Jeff Epstein</name>
<email>[email protected]</email>
<roles>
<role>Lead Developer</role>
</roles>
</developer>
</developers>
<issueManagement>
<system>GitHub Issue Tracker</system>
<url>https://github.com/aliteralmind/xbnjava/issues</url>
</issueManagement>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:git:[email protected]:aliteralmind/xbnjava.git</connection>
<url>scm:git:[email protected]:aliteralmind/xbnjava.git</url>
<developerConnection>scm:git:[email protected]:aliteralmind/xbnjava.git</developerConnection>
</scm>
<properties>
<java.version>1.7</java.version>
<jarprefix>R:\jeffy\programming\build\/${project.artifactId}-${project.version}/download/${project.artifactId}-${project.version}</jarprefix>
</properties>
<!--
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
-->
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${jarprefix}-all.jar</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<!--
This profile will sign the JAR file, sources file, and javadocs file using the GPG key on the local machine.
See: https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven
-->
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>release</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
</project>
------------------
------------------
Full logs for mvn deploy
and mvn deploy -e
对于全日志mvn deploy
和mvn deploy -e
mvn deploy
output:
mvn deploy
输出:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.2
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ xbnjava ---
[INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-artifacts) @ xbnjava ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\z__for_git_commit_only\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.204 s
[INFO] Finished at: 2014-07-18T11:25:17-04:00
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. 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
.1.2\xbnjava-0.1.2.pom
[INFO] Installing R:\jeffy\programming\build\xbnjava-0.1.2\download\xbnjava-0.1.2-all.jar to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.2
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ xbnjava ---
[INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-artifacts) @ xbnjava ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\z__for_git_commit_only\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.492 s
[INFO] Finished at: 2014-07-18T11:25:37-04:00
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:193)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)
at org.apache.maven.plugin.deploy.AbstractDeployMojo.deploy(AbstractDeployMojo.java:167)
at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:149)
... 21 more
Caused by: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:337)
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:268)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:413)
at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:139)
... 23 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact com.github.aliteralmind:xbnjava:pom:0.1.2 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.wrap(WagonRepositoryConnector.java:1016)
at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.wrap(WagonRepositoryConnector.java:1004)
at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$PutTask.run(WagonRepositoryConnector.java:895)
at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.put(WagonRepositoryConnector.java:522)
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:331)
... 26 more
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:573)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:493)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:474)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:454)
at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$PutTask.run(WagonRepositoryConnector.java:871)
... 28 more
[ERROR]
[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
.1.2\xbnjava-0.1.2.pom
[INFO] Installing R:\jeffy\programming\build\xbnjava-0.1.2\download\xbnjava-0.1.2-all.jar to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava <server>
<id>nexus-snapshots</id>
<username>MY_SONATYPE_DOT_COM_USERNAME</username>
<password>MY_SONATYPE_DOT_COM_PASSWORD</password>
</server>
.1.2\xbnjava-0.1.2.jar
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom
2/6 KB
4/6 KB
6/6 KB
.1.2\xbnjava-0.1.2.jar
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.2/xbnjava-0.1.2.pom
2/6 KB
4/6 KB
6/6 KB
(Failure section:)
(失败部分:)
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
and then make sure that lines up with what's in your settings.xml:
<settings>
<servers>
<server>
<id>ossrh</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>
</settings>
mvn deploy -e
output:
mvn deploy -e
输出:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-artifacts) @ xbnjava ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\z__for_git_commit_only\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjavaUploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.jar (630 KB at 474.7 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.632 s
[INFO] Finished at: 2014-07-18T15:09:25-04:00
[INFO] Final Memory: 6M/19M
[INFO] ------------------------------------------------------------------------
.1.3\xbnjava-0.1.3.pom
[INFO] Installing R:\jeffy\programming\build\xbnjava-0.1.3\download\xbnjava-0.1.3.jar to C:\Users\jeffy\.m2\repository\com\github\aliteralmind\xbnjava<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.aliteralmind</groupId>
<artifactId>xbnjava</artifactId>
<packaging>pom</packaging>
<version>0.1.3</version>
<name>XBN-Java</name>
<url>https://github.com/aliteralmind/xbnjava</url>
<inceptionYear>2014</inceptionYear>
<organization>
<name>Jeff Epstein</name>
</organization>
<description>XBN-Java is a collection of generically-useful backend (server side, non-GUI) programming utilities, featuring RegexReplacer and FilteredLineIterator. XBN-Java is the foundation of Codelet (http://codelet.aliteralmind.com).</description>
<licenses>
<license>
<name>Lesser General Public License (LGPL) version 3.0</name>
<url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
</license>
<license>
<name>Apache Software License (ASL) version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>Jeff Epstein</name>
<email>[email protected]</email>
<roles>
<role>Lead Developer</role>
</roles>
</developer>
</developers>
<issueManagement>
<system>GitHub Issue Tracker</system>
<url>https://github.com/aliteralmind/xbnjava/issues</url>
</issueManagement>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:git:[email protected]:aliteralmind/xbnjava.git</connection>
<url>scm:git:[email protected]:aliteralmind/xbnjava.git</url>
<developerConnection>scm:git:[email protected]:aliteralmind/xbnjava.git</developerConnection>
</scm>
<properties>
<java.version>1.7</java.version>
<jarprefix>R:\jeffy\programming\build\/${project.artifactId}-${project.version}/download/${project.artifactId}-${project.version}</jarprefix>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${jarprefix}.jar</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<!--
This profile will sign the JAR file, sources file, and javadocs file using the GPG key on the local machine.
See: https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven
-->
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>release</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
</project>
.1.3\xbnjava-0.1.3.jar
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.pom
2/6 KB
4/6 KB
6/6 KB
Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.pom (6 KB at 4.6 KB/sec)
Downloading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml
310/310 B
Downloaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml (310 B at 1.6 KB/sec)
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml
310/310 B
Uploaded: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/maven-metadata.xml (310 B at 1.4 KB/sec)
Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/github/aliteralmind/xbnjava/0.1.3/xbnjava-0.1.3.jar
2/630 KB
4/630 KB
6/630 KB
8/630 KB
10/630 KB
12/630 KB
14/630 KB
...
618/630 KB
620/630 KB
622/630 KB
624/630 KB
626/630 KB
628/630 KB
630/630 KB
(Failure section:)
(失败部分:)
[DEBUG] Using connector AetherRepositoryConnector with priority 3.4028235E38 for http://www:8081/nexus/content/repositories/snapshots/
[INFO] Downloading: http://www:8081/nexus/content/repositories/snapshots/com/wdsuite/com.wdsuite.server.product/1.0.0-SNAPSHOT/maven-metadata.xml
[DEBUG] Could not find metadata com.group:artifact.product:version-SNAPSHOT/maven-metadata.xml in nexus (http://www:8081/nexus/content/repositories/snapshots/)
[DEBUG] Writing tracking file /home/me/.m2/repository/com/group/project/version-SNAPSHOT/resolver-status.properties
[INFO] Uploading: http://www:8081/nexus/content/repositories/snapshots/com/...-1.0.0-20141118.124526-1.zip
[INFO] Uploading: http://www:8081/nexus/content/repositories/snapshots/com/...-1.0.0-20141118.124526-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
采纳答案by John
I've had similar errors when trying to deploy a Gradle artefact to a Nexus Sonatype repository. You will get a 401 Unauthorized error if you supply the wrong credentials (password etc). You also get an error (and off the top of my head is also a 401) if you try to publish something to a releases repository and that version already exists in the repository.So you might find that by publishing from the command line it works, but then when you do it from a script it fails (because it didn't exist in the repository the first time around). Either publish using a different version number, or delete the old artefact on the server and republish.
尝试将 Gradle 人工制品部署到 Nexus Sonatype 存储库时,我遇到了类似的错误。如果您提供错误的凭据(密码等),您将收到 401 Unauthorized 错误。如果您尝试将某些内容发布到发布存储库并且该版本已存在于存储库中,您也会收到一个错误(我的头顶也是 401)。因此,您可能会发现通过从命令行发布它可以工作,但是当您从脚本执行它时它会失败(因为它第一次不存在于存储库中)。要么使用不同的版本号发布,要么删除服务器上的旧工件并重新发布。
The SNAPSHOTS repository (as opposed to the releases repository) allows you to overwrite a similarly numbered version, but your version number should have "-SNAPSHOT" at the end of it.
SNAPSHOTS 存储库(与发布存储库相反)允许您覆盖类似编号的版本,但您的版本号末尾应带有“-SNAPSHOT”。
回答by Moe Singh
just change in settings.xml these as aliteralmind says:
正如 aliteralmind 所说,只需在 settings.xml 中更改这些:
curl -u username:password http://url/artifactory/libs-snapshot-local/com/myproject/api/1.0-SNAPSHOT/api-1.0-20160128.114425-1.jar --request PUT --data target/api-1.0-SNAPSHOT.jar
you probably need to get the username / password from sonatype dot com.
您可能需要从 sonatype dot com 获取用户名/密码。
回答by aliteralmind
As stated in @John's answer, the fact that there is already a 0.1.2-SNAPSHOT
, interfered with my new non-SNAPSHOT version 0.1.2
. Since the 401 Unauthorized
error is nebulous and unhelpful--and is normally associated to user/pass problems--it's no surprise that I was unable to figure this out on my own.
正如@John 的回答中所述,事实上已经有一个0.1.2-SNAPSHOT
, 干扰了我的新非 SNAPSHOT 版本0.1.2
。由于该401 Unauthorized
错误是模糊且无益的——并且通常与用户/通行证问题相关——因此我无法自己解决这个问题也就不足为奇了。
Changing the version to 0.1.3
brings me back to my original error:
更改版本0.1.3
使我回到原来的错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project xbnjava: Failed to install artifact com.github.aliteralmind:xbnjava:jar:0.1.3: R:\jeffy\programming\build\xbnjava-0.1.3\download\xbnjava-0.1.3-all.jar (The system cannot find the path specified) -> [Help 1].
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project xbnjava: Failed to install artifact com.github.aliteralmind:xbnjava:jar:0.1.3: R:\jeffy\programming\build\xbnjava-0.1.3\download\xbnjava-0.1.3-all.jar (The system cannot find the path specified) -> [Help 1].
A sonatype support person also recommended that I remove the <parent>
block from my POM (it's only there because it's in the one from ez-vcard, which is what I started with) and replace my <distributionManagement>
block with
一位 sonatype 支持人员还建议我<parent>
从我的 POM 中删除该块(它只是在那里,因为它在ez-vcard 中,这是我开始使用的)并将我的<distributionManagement>
块替换为
{
"errors" : [ {
"status" : 401,
"message" : "Artifactory configured to accept only encrypted passwords but received a clear text password."
} ]
}
After doing this, running mvn deploy
actually uploaded one of my jars for the very first time!!!
这样做之后,runmvn deploy
实际上第一次上传了我的一个罐子!!!
Output:
输出:
<servers>
<server>
<id>snapshot-repository</id> <!-- must match this -->
<username>deployment</username>
<password>password</password>
</server>
</servers>
(Success portion:)
(成功部分:)
[DEBUG] (f) offline = false
[DEBUG] (f) packaging = exe
[DEBUG] (f) pomFile = c:\temp\build-test\pom.xml
[DEBUG] (f) project = MavenProject: org.apache.maven:standalone-pom:1 @
[DEBUG] (f) repositoryId = remote-repository
[DEBUG] (f) repositoryLayout = default
[DEBUG] (f) retryFailedDeploymentCount = 1
[DEBUG] (f) uniqueVersion = true
[DEBUG] (f) updateReleaseInfo = false
[DEBUG] (f) url = https://nexus.url.blah.com/...
[DEBUG] (f) version = 13.1
[DEBUG] -- end configuration --
Here's the full updated POM:
这是完整更新的 POM:
##代码##That's one big Maven problem out of the way. Only 627 more to go.
这是 Maven 的一大问题。仅剩 627 辆。
回答by Betty Sanchez
I had the same error. I tried and rechecked everything. I was so focused in the Stack trace that I didn't read the last lines of the build before the Reactor summary and the stack trace:
我有同样的错误。我尝试并重新检查了一切。我太专注于堆栈跟踪,以至于我没有在 Reactor 摘要和堆栈跟踪之前阅读构建的最后几行:
##代码##This was the key : "Could not find metadata". Although it said that it was an authentication error actually it got fixed doing a "rebuild metadata" in the nexus repository.
这是关键:“找不到元数据”。尽管它说这是一个身份验证错误,但实际上它在 nexus 存储库中通过“重建元数据”得到了修复。
Hope it helps.
希望能帮助到你。
回答by Grant Currey
We have had this issue quite recently and found out it was to do with the version of Maven we were using. We were using 3.1.0 and could not upload to nexus, we kept getting 401's, we reverted back to 3.0.3 and the issue went away.
我们最近遇到了这个问题,并发现它与我们使用的 Maven 版本有关。我们使用的是 3.1.0 并且无法上传到 nexus,我们不断收到 401,我们恢复到 3.0.3 并且问题消失了。
Easiest way to confirm is to work through the maven versions and run "mvn deploy" on your project.
确认的最简单方法是通过 maven 版本并在您的项目上运行“mvn deploy”。
Further details can be found here: https://issues.apache.org/jira/browse/WAGON-421
可以在此处找到更多详细信息:https: //issues.apache.org/jira/browse/WAGON-421
回答by rwitzel
Some users may have entered the email address instead of the user name by mistake. This may happen unconsciously when the name in the email address is the same as the user name.
有些用户可能错误地输入了电子邮件地址而不是用户名。当电子邮件地址中的名称与用户名相同时,这可能会在不知不觉中发生。
回答by Alberto M
I had put a not encrypted password in the settings.xml .
我在 settings.xml 中放置了一个未加密的密码。
I tested the call with curl
我用 curl 测试了通话
##代码##and I got the error:
我得到了错误:
##代码##I retrieved my encrypted password clicking on my artifactory profile and unlocking it.
我检索了我的加密密码,点击我的神器配置文件并解锁它。
回答by Rumesh Bandara
This is the official explanation from sonatype nexus team about 401 - Unauthorized
这是sonatype nexus团队关于401的官方解释- 未经授权
I recommend you to read Troubleshooting Artifact Deployment Failuresfor more information.
我建议您阅读故障排除工件部署故障以获取更多信息。
Code 401 - Unauthorized
Either no login credentials were sent with the request, or login credentials which are invalid were sent. Checking the "authorization and authentication" system feed in the Nexus UI can help narrow this down. If credentials were sent there will be an entry in the feed.
If no credentials were sent this is likely due to a mis-match between the id in your pom's distributionManagement section and your settings.xml's server section that holds the login credentials.
代码 401 - 未经授权
没有随请求发送登录凭据,或者发送了无效的登录凭据。检查 Nexus UI 中的“授权和身份验证”系统提要可以帮助缩小范围。如果发送了凭据,则提要中将有一个条目。
如果没有发送凭据,这可能是由于 pom 的 distributionManagement 部分中的 id 与保存登录凭据的 settings.xml 的服务器部分中的 ID 不匹配。
回答by Forge_7
Also had 401's from Nexus. Having tried all the suggestions above and more without success I eventually found that it was a Jenkins setting that was in error.
也有来自 Nexus 的 401。在尝试了上述所有建议以及更多但没有成功之后,我最终发现这是一个 Jenkins 设置错误。
In the Jenkins configuration for the failing project, we have a section in the 'Post Build' actions entitled 'Deploy Artifacts To Maven Repository'. This has a 'Repository ID' field which was set to the wrong value. It has to be the same as the repository ID in settings.xml for Jenkins to read the user and password fields:
在失败项目的 Jenkins 配置中,我们在“构建后”操作中有一个名为“将工件部署到 Maven 存储库”的部分。这有一个设置为错误值的“存储库 ID”字段。它必须与 settings.xml 中的存储库 ID 相同,以便 Jenkins 读取用户和密码字段:
##代码##回答by Jay Random
One of the reasons for this error is when repositoryId is not specified or specified incorrectly. As mentioned already it should be the same as in section in settings.xml. Couple of hints... Run mvn with -e -X options and check the debug output. It will tell you which repositoryId it is using:
此错误的原因之一是未指定或指定不正确的 repositoryId。如前所述,它应该与 settings.xml 中的部分相同。几个提示...使用 -e -X 选项运行 mvn 并检查调试输出。它会告诉你它使用的是哪个 repositoryId:
##代码##In this case it uses the default value "remote-repository", which means that something went wrong.
在这种情况下,它使用默认值“remote-repository”,这意味着出现问题。
Apparently I have specified -DrepositoryID (note ID in capital) instead of -DrepositoryId.
显然我指定了 -DrepositoryID(注意大写 ID)而不是 -DrepositoryId。