Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在URL中没有用户名和密码的情况下从我自己的经过身份验证的nexus获取maven原型?_Maven_Nexus_Maven Archetype_Sonatype - Fatal编程技术网

如何在URL中没有用户名和密码的情况下从我自己的经过身份验证的nexus获取maven原型?

如何在URL中没有用户名和密码的情况下从我自己的经过身份验证的nexus获取maven原型?,maven,nexus,maven-archetype,sonatype,Maven,Nexus,Maven Archetype,Sonatype,我有一个私有的Nexus,它有一个通过身份验证保护的存储库 拉取库就像一种魅力,但如果我想使用其中一个存储在那里的原型,我总是需要在原型目录的URL中写入明文用户名和密码,如下所示: mvn archetype:generate -DarchetypeCatalog=http://username:password@maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml 我阅读并更新了我的setti

我有一个私有的Nexus,它有一个通过身份验证保护的存储库

拉取库就像一种魅力,但如果我想使用其中一个存储在那里的原型,我总是需要在原型目录的URL中写入明文用户名和密码,如下所示:

mvn archetype:generate -DarchetypeCatalog=http://username:password@maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
我阅读并更新了我的settings.xml,这是我从一点点帮助中了解到的:

<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>myrepo</id>
      <username>username</username>
      <password>{HASHED_PASSWORD}</password>
    </server>
    <server>
      <id>pretty-archetype-unicorn-repo</id>
      <username>username</username>
      <password>{HASHED_PASSWORD}</password>
    </server>
  </servers>

  <profiles>
   <profile>
     <id>someid</id>
     <repositories>
       <repository>
         <id>myrepo</id>
         <name>My Repo</name>
         <url>http://maven.mycompany.com/nexus/content/repositories/myrepo/</url>
       </repository>
     </repositories>
   </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>someid</activeProfile>
  </activeProfiles>

</settings>
我得到了同样的答案:

[WARNING] Error reading archetype catalog http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
org.apache.maven.wagon.authorization.AuthorizationException: Access denied to: http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml

是否有任何提示或更好的工作示例文档?

如果您不至少指定
-DarchetypeArtifactId
,则目前无法实现此目的。根据您链接的官方文档:

The server id used to download the artifact is [archetypeArtifactId]-repo
因此,如果目录受密码保护(并且您不愿意在shell历史记录中公开用户名/密码),则无法仅浏览目录

与此同时,你可以继续投票支持他们。他们有一个补丁已经提供了多年,他们可能只需要一点推动

更新

查看maven原型项目的详细信息,可以看到
settings.xml
中的以下代码片段可能适合您:

<servers>
    <server>
      <id>archetype</id>
      <username>${your username}</username>
      <password>${your password}</password>
    </server>
</servers>

原型
${您的用户名}
${您的密码}
获取远程目录时,在构建
存储库
对象时,默认ID为
原型
。我不认为这是处理这种情况的官方方式,而且在我看来有点脏。但它可能仍然适用于你:-)


此外,您应该能够设置配置文件,以便为不同的服务器重用
原型
ID。

我认为应该在您的settings.xml中

<servers>
    <server>
      <id>myrepo</id>
      <username>${your username}</username>
      <password>${your password}</password>
    </server>
</servers>

myrepo
${您的用户名}
${您的密码}

您需要为每个受密码保护的存储库添加

看起来这是一个已知问题,您无法使用受保护存储库中的原型。看

通过执行以下操作,可以找到解决方法:

mvn archetype:generate -DarchetypeCatalog=https://username:password@maven.mycompany.com/nexus/content/repositories/myrepo/

听起来很有希望,谢谢。我会尽快试一试,并报告我的发现@尼古拉斯:我也没有运气。我升级了bug并写了评论。另一个选项是将MAVEN_OPTS与这个
-DarchetypeCatalog=…
一起使用,但这是一个相当肮脏的解决方法。
mvn archetype:generate -DarchetypeCatalog=https://username:password@maven.mycompany.com/nexus/content/repositories/myrepo/