Maven未经授权,ReasonPhrase:未经授权

Nuñ*_*ada 5 maven

我试图从Nexus存储库中查看我的代码.首先,我用密码生成密码

mvn --encrypt-master-password _mypassword_
Run Code Online (Sandbox Code Playgroud)

这是我的c:/Users/joanet/.m2/settings-security.xml:

<settingsSecurity>
<master>{TnRCVc3cX6MH5qRXEMLwxjKGfXQu6v/6wR0rgHED2ws=}</master>
</settingsSecurity>
Run Code Online (Sandbox Code Playgroud)

这是我的c:/progs/PGM/apache-maven-3.0.5/conf/settings.xml

  <?xml version="1.0" encoding="UTF-8"?>

    <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
    license agreements. See the NOTICE file distributed with this work for additional
    information regarding copyright ownership. The ASF licenses this file to
    you under the Apache License, Version 2.0 (the "License"); you may not use
    this file except in compliance with the License. You may obtain a copy of
    the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
    by applicable law or agreed to in writing, software distributed under the
    License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
    OF ANY KIND, either express or implied. See the License for the specific
    language governing permissions and limitations under the License. -->

    <!-- http://maven.apache.org/settings.html -->
    <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">

    <localRepository>C:/Users/joanet/.m2/repository</localRepository>


    <proxies>
     <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>joanet</username>
      <password>{TnRCVc3cX6MH5qRXEMLwxjKGfXQu6v/6wR0rgHED5ws=}</password>
      <host>157.129.133.11</host>
      <port>8032</port>
      <nonProxyHosts>localhost</nonProxyHosts>
     </proxy>
    </proxies>

    <servers>
      <server>
       <id>ecPublicRepository</id>
       <username>joanet</username>
       <password>{TnRCVc3cX6MH5qRXEMLwxjKGfXQu6v/6wR0rgHED5ws=}</password>
      </server>


    </servers>

    <mirrors></mirrors>

    <pluginGroups>
     <!-- pluginGroup Specifies a further group identifier to use for plugin lookup.  -->
     <pluginGroup>com.oracle.weblogic</pluginGroup>
     <pluginGroup>com.github.searls</pluginGroup>
     <pluginGroup>com.cj.jshintmojo</pluginGroup>
     <pluginGroup>com.github.phasebash</pluginGroup>

    </pluginGroups>

    <profiles>
     <profile>
      <id>activeProfile</id>

      <repositories>

       <repository>
          <id>ecPublicRepository</id>
          <url>https://foo.com/nexus/content/groups/public/</url>
       </repository>


      </repositories>

      <pluginRepositories>

       <pluginRepository>
        <id>PublicRepository</id>
        <name>Public Repository</name>
        <url>https://foo.com/nexus/content/groups/public/</url>
       </pluginRepository>
      </pluginRepositories>

     </profile>

    </profiles>

    <!-- activeProfiles | List of profiles that are active for all builds. | -->
    <activeProfiles>
     <activeProfile>activeProfile</activeProfile>
    </activeProfiles>


    </settings>
Run Code Online (Sandbox Code Playgroud)

但这是错误:

Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could not
 transfer artifact org.apache.maven.plugins:maven-install-plugin:pom:2.3.1 from/
to ecPublicRepository (https://foo.com/nexus/content/groups/public/): Not authorized , ReasonPhrase:Unauthorized.
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(Def
aultArtifactResolver.java:538)
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArti
facts(DefaultArtifactResolver.java:216)
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArti
fact(DefaultArtifactResolver.java:193)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.
loadPom(DefaultArtifactDescriptorReader.java:281)
        ... 28 more
Run Code Online (Sandbox Code Playgroud)

Tim*_*imo 12

加密主密码后,还应加密nexus所需的实际密码.因此,散列值settings-security.xml应该与您在服务器配置中使用的实际值不同.

您可以按照以下步骤操作(取自此处):

使用以下命令行:

mvn --encrypt-master-password <password>
Run Code Online (Sandbox Code Playgroud)

注意:由于Maven 3.2.1密码是可选参数.如果没有提供,Maven将提示输入密码.早期版本的Maven不会提示输入密码,因此必须在明文的命令行中输入密码.有关详细信息,请参阅以下提示

此命令将生成密码的加密版本,例如

{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}
Run Code Online (Sandbox Code Playgroud)

将此密码存储在〜/ .m2/settings-security.xml中; 它应该看起来像

<settingsSecurity>
<master>{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</master>
</settingsSecurity>
Run Code Online (Sandbox Code Playgroud)

完成此操作后,您可以开始加密现有服务器密码.如何加密服务器密码

您将必须使用以下命令行:

mvn --encrypt-password <password>
Run Code Online (Sandbox Code Playgroud)

注意:就像--encrypt-master-password一样,密码参数是可选的,因为Maven 3.2.1.

这个命令会产生一个加密版本,比如说

{COQLCE6DU6GtcS5P=}
Run Code Online (Sandbox Code Playgroud)

将其剪切粘贴到服务器部分的settings.xml文件中.这看起来像:

<settings>
...
<servers>
...
<server>
<id>my.server</id>
<username>foo</username>
<password>{COQLCE6DU6GtcS5P=}</password>
</server>
...
</servers>
...
</settings>
Run Code Online (Sandbox Code Playgroud)

请注意,密码可以包含大括号之外的任何信息,以便以下内容仍然有效: