Maven:未能部署工件,访问被拒绝

Maven:未能部署工件,访问被拒绝,maven,nexus,Maven,Nexus,我有一个Sonatype Nexus服务器,我想部署一个快照 这是my settings.xml文件的一个片段: <servers> <server> <id>test-snapshots</id> <username>myname1</username> <password>mypasswd1</password> </server> <serv

我有一个Sonatype Nexus服务器,我想部署一个快照

这是my settings.xml文件的一个片段:

<servers>
  <server>
    <id>test-snapshots</id>
    <username>myname1</username>
    <password>mypasswd1</password>
  </server>
  <server>
    <id>test-releases</id>
    <username>myname2</username>
    <password>mypasswd2</password>
  </server>
</servers>
<distributionManagement>
  <repository>
    <id>test-releases</id>
    <name>Releases</name>
    <url>https://nxs.company.com/content/repositories/test-releases</url>
  </repository>
  <snapshotRepository>
    <id>test-snapshots</id>
    <name>Snapshots</name>
    <url>https://nxs.company.com/content/repositories/test-snapshots</url>
  </snapshotRepository>
</distributionManagement>
<settings>
    <servers>
        <server>
            <id>test-snapshots</id>
            <username>myname1</username>
            <password>mypasswd1</password>
        </server>
        <server>
            <id>test-releases</id>
            <username>myname2</username>
            <password>mypasswd2</password>
        </server>
    </servers>
</settings>
在我的Nexus日志文件中,我看到没有收到任何凭据,所以它稍后将使用anonymous进行尝试,这当然会失败。那么为什么没有凭证传递给Nexus呢

2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.apache.shiro.session.mgt.DefaultSessionManager - Unable to resolve session ID from SessionKey [org.apache.shiro.web.session.mgt.WebSessionKey@791a17dc].  Returning null to indicate a session could not be found.
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - No authorization found (header or request parameter)
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - No authorization found (header or request parameter)
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - Attempting to authenticate Subject as Anonymous request...
2012-10-04 17:24:14 DEBUG [1027496148-8353] - org.sonatype.security.ldap.realms.DefaultLdapContextFactory - Initializing LDAP context using URL [ldap://10.100.100.1:3268/DC=company,DC=com] and username [ldap@company.com] with pooling [enabled]

Nexus中的每个存储库是否确实有不同的用户名/密码?这将导致maven http旅行车出现问题,因为jvm会为每个主机缓存凭据,即使maven正确地提供备用凭据,jvm也不会使用它们。解决方法是使用webdav,因为它使用apache http客户端而不是jdk urlclient。

我们的nexus服务器有多个帐户。在windows user_home/.m2/设置中,它具有:

    <server>
        <!-- this id should match the id of the repo server in pom.xml -->
        <id>release-nexus</id>
        <username>aa</username>
        <password>AA</password>
    </server>
    <server>
        <!-- this id should match the id of the repo server in pom.xml -->
        <id>snapshots-nexus</id>
        <username>aa</username>
        <password>AA</password>
    </server>

释放关系
aa
AA
快照关系
aa
AA
在项目中:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>some.groupid</groupId>
  <artifactId>some-demo</artifactId>
  <version>1.0.0</version>
  
  <distributionManagement>
    <repository>
      <id>release-nexus</id>  
      <name>Maven Repository Switchboard</name>  
      <url>http://nexus.foo.net/nexus/content/repositories/aa/</url> 
    </repository>

    <snapshotRepository>
      <id>snapshots-nexus</id>  
      <name>Maven Repository Switchboard</name>  
      <url>http://nexus.foo.net/nexus/content/repositories/aa_snapshot/</url>  
    </snapshotRepository>
  </distributionManagement>
</project>

4.0.0
some.groupid


在设置中配置的所有
与我们在project pom
distributionManagement
中使用的不同。如果我在pom的设置中输入了什么,它将导致相同的错误
禁止
。当我使用用户名和密码
aa
aa
登录nexus server时,我找到了正确的url,我发现有一个
aa
aa\u snapshort
。因此,我猜
PUT
操作的权限实际上更为详细。

您需要“settings”元素作为root,
将其放入settings.xml文件:

<servers>
  <server>
    <id>test-snapshots</id>
    <username>myname1</username>
    <password>mypasswd1</password>
  </server>
  <server>
    <id>test-releases</id>
    <username>myname2</username>
    <password>mypasswd2</password>
  </server>
</servers>
<distributionManagement>
  <repository>
    <id>test-releases</id>
    <name>Releases</name>
    <url>https://nxs.company.com/content/repositories/test-releases</url>
  </repository>
  <snapshotRepository>
    <id>test-snapshots</id>
    <name>Snapshots</name>
    <url>https://nxs.company.com/content/repositories/test-snapshots</url>
  </snapshotRepository>
</distributionManagement>
<settings>
    <servers>
        <server>
            <id>test-snapshots</id>
            <username>myname1</username>
            <password>mypasswd1</password>
        </server>
        <server>
            <id>test-releases</id>
            <username>myname2</username>
            <password>mypasswd2</password>
        </server>
    </servers>
</settings>

测试快照
我的名字1
mypasswd1
测试版本
我的名字2
mypasswd2

您是否已验证您的用户帐户具有该特定存储库的权限?请参阅:是的,用户具有该权限。但用户似乎无法登录,因为请求中没有凭据。Nexus“authorization and authentication events”系统提要中有什么内容?乍一看,所有内容都设置正确。能否在web浏览器中打开快照存储库url,并使用
settings.xml
中的凭据访问存储库的内容?另外,您可以尝试使用
-X
执行deploy以获取调试信息(可能会显示一些信息)。我已经使用了
-X
标志,但没有更多信息。是的,我可以访问快照存储库url,它包含一个文件
arcehtype catalog.xml
,只有一行
。登录到Nexus前端,我在日志文件中看到“使用来自请求的授权头”。如果我想部署,这是不存在的。对于我的Nexus repo,我有一个用户名/密码组合,但我还集成了一些其他需要不同用户名/密码的存储库。所以,如果我只使用一个用户名/密码组合,它必须工作?WebDav旅行车?我如何使用它,这意味着什么?