【问题标题】:maven can't find archetype in my repositorymaven 在我的存储库中找不到原型
【发布时间】:2011-09-23 09:43:05
【问题描述】:

我正在尝试创建自己的 Maven 原型。现在,我正在 [here][1] 完成本教程,但没有成功。我可以构建原型项目,但是当我尝试从该原型生成项目时,我收到以下错误。 Maven 似乎找不到我创建的原型。谁能发现我的问题?是否有其他推荐的教程来创建 Maven 原型?谢谢。

Maven 版本 3.0.3

构建错误:

AR3Y35-LAPTOP:EclipseWS Albert$ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeGroupId=com.myarch.archetypes -DarchetypeArtifactId=component-archetype -DinteractiveMode=false 
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom <<<
[INFO] 
[INFO] --- maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] Specified archetype not found.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.389s
[INFO] Finished at: Fri Sep 23 02:33:55 PDT 2011
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.0:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.myarch.archetypes:component-archetype:1.0) -> [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/MojoFailureException
AR3Y35-LAPTOP:EclipseWS Albert$ 

原型 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>

  <parent>
    <groupId>com.myarch.templates</groupId>
    <artifactId>component-template</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>${groupId}</groupId>
  <artifactId>${artifactId}</artifactId>
  <version>${version}</version>

  <name>${group}</name>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

</project>

archetype.xml

<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">
  <id>component-archetype</id>
  <sources>
    <source>src/main/java/App.java</source>
  </sources>
  <testSources>
    <source>src/test/java/AppTest.java</source>
  </testSources>
  <allowPartial>true</allowPartial>
</archetype>

【问题讨论】:

    标签: maven maven-3 maven-plugin maven-archetype


    【解决方案1】:

    为了使用自定义原型,必须在位于您主目录中的.m2/repository/archetype-catalog.xmlarchetype-catalog.xml 文件中创建一个条目。为此,您需要使用以下命令安装原型:

    mvn install archetype:update-local-catalog
    

    之后,您将能够在使用 mvn archetype:generate 命令创建新的 Maven 项目时使用新原型。

    【讨论】:

      【解决方案2】:

      我需要在 mvn archetpe:generate 命令中包含 -DarchetypeVersion={my.archetype.version}

      【讨论】:

      • 这部分我错了。我指定了错误的原型版本。
      【解决方案3】:

      就我而言,问题在于: - update-local-catalog 目标创建文件 ~/.m2/repository/archetype-catalog.xml - generate 目标搜索文件 ~/.m2/archetype-catalog.xml 复制文件是一种解决方法。不知道我是如何解决这个问题的。当然现在使用 maven 3.5.4 一切正常。

      【讨论】:

        【解决方案4】:

        它告诉你:

        [WARNING] Specified archetype not found.
        

        您是否使用

        安装了原型
        mvn install
        

        在尝试使用之前?

        【讨论】:

        • 是的...mvn 全新安装。谢谢
        【解决方案5】:

        执行 mvn install 解决了问题,在从 idea 执行之后问题得到了解决。

        【讨论】:

          【解决方案6】:

          根据我自己的经验,您必须在下面的链接中搜索您的 groupId 是否可以访问

          http://repo.maven.apache.org/maven2/archetype-catalog.xml

          我发现我有拼写错误然后我有错误。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-08-20
            • 1970-01-01
            • 2011-06-25
            • 1970-01-01
            • 2016-06-23
            • 2015-02-17
            • 2014-06-28
            • 2017-02-16
            相关资源
            最近更新 更多