简体   繁体   English

在尝试访问nexus私有存储库时,maven收到“Not Authorized”

[英]maven getting “Not Authorized” when trying to access nexus private repository

I've set up a private nexus repo manager on an EC2 instance and followed the various instructions floating around the internet on how to set up a maven project to use it. 我在EC2实例上设置了一个私有nexus repo管理器,并按照互联网上的各种说明,了解如何设置maven项目来使用它。 I have also disabled the anonymous account. 我也禁用了匿名帐户。 I am able to connect and copy repositories via curl -U username:password <the_url> and it seems to work fine. 我能够通过curl -U username:password <the_url>连接和复制存储库,它似乎工作正常。 However when I try to use maven (any goals) The very first thing I get is 然而,当我尝试使用maven(任何目标)时,我得到的第一件事就是

    [WARNING] Could not transfer metadata org.apache.maven.plugins:maven-compiler-plugin/maven-metadata.xml from/to nexus (http://MY_NEXUS_HOST:8081/nexus/content/groups/public): Not authorized , ReasonPhrase:Unauthorized.

The mvn command then fails because it can't find the plugin anywhere. 然后mvn命令失败,因为它无法在任何地方找到插件。 So the fact that I can use the rest command and it works as expected, but not through maven indicates to me that it is a problem with the configuration. 所以我可以使用rest命令并且它按预期工作,但不是通过maven这一事实告诉我,这是配置问题。 I think I understand what's going on pretty well, and I've checked and rechecked the files, but I don't see anything wrong. 我想我明白发生了什么,我检查并重新检查了文件,但我没有看到任何错误。 Here's the settings.xml file 这是settings.xml文件

 <servers> <server> <id>nexus-snapshot</id> <username>USER_NAME</username> <password>USER_PASSWD</password> </server> <server> <id>nexus-release</id> <username>USER_NAME</username> <password>USER_PASSWD</password> </server> </servers> <mirrors> <mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--Enable snapshots for the built in central repo to direct --> <!--all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles> 

And here is the relevent portion of the pom file 这是pom文件的相关部分

    <distributionManagement>
        <repository>
            <id>nexus-release</id>
            <name>Nexus Release Repository</name>
            <url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshot</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

I'm wondering if there's a way to see the exact issue I'm running into. 我想知道是否有办法看到我遇到的确切问题。 For instance, if I'm getting a 401, 403 or (for some reason?) 404. If someone can please help me I'd be ever so greatful. 例如,如果我得到401,403或(由于某种原因?)404。如果有人可以请求帮助我,我会非常好。 Oh, both maven and nexus are the latest versions as of last week. 哦,maven和nexus都是上周的最新版本。 *edited because no matter how many times you check something before hitting submit... *编辑,因为无论您在点击提交之前检查了多少次...

Oh my funky goat. 哦,我的时髦山羊。 The problem was that apparently in settings.xml, the Id field has to be the same as the one in the server field. 问题是显然在settings.xml中,Id字段必须与服务器字段中的Id字段相同。 ie: 即:

<servers>
 <server>
      <id>nexus-release</id>          <---THIS MUST MATCH
      <username>USER_NAME</username>
      <password>USER_PASSWD</password>
  </server>
</servers>
<mirrors>
    <mirror>
      <id>nexus-release</id>          <---THIS
      <mirrorOf>*</mirrorOf>
      <url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

I guess it doesn't matter which one I use (they're both the same in this case, but that's not necessarily always true). 我想我使用哪一个并不重要(在这种情况下它们都是相同的,但并不一定总是如此)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM