繁体   English   中英

安装使用 mvn archetype:create-from-project 创建的多模块原型时出错

[英]Error installing a multimodule archetype created with mvn archetype:create-from-project

我有一个具有以下结构的项目:

项目 (pom)
项目客户端(模块,jar)
项目-ejb(模块,jar)
项目网络(模块,战争)
项目耳(模块,耳)

在 pom 中,模块使用以下方法引用父级:

<relativePath>../project</relativePath>

并且根 pom 以相同的方式引用模块(使用 ../)。

我可以使用 archetype:create-from-project 创建原型,并且一切运行顺利。

但是当我尝试安装原型(mvn install 在目标/生成源/原型目录中)时,我收到错误:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:integration-test (default-integration-test) on project seguranca-archetype:
    [ERROR] Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
    [ERROR] -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:integration-test (default-integration-test) on project seguranca-archetype: 
    Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    Caused by: org.apache.maven.plugin.MojoExecutionException: 
    Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
        at org.apache.maven.archetype.mojos.IntegrationTestMojo.execute(IntegrationTestMojo.java:268)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more

问题是该文件存在(它在 target/generated-sources/archetype/src/main/resources/__rootArtifactId__client/pom.xml 上),我试图摆弄 archetype-metadata.xml 没有成功。 有什么线索吗?

提前致谢

看起来原型插件不支持多模块项目的平面布局。 如果是这种情况,解决方法是更改​​为嵌套布局。 我通过将 archetype-resources 目录之外的模块移到其中来做到这一点。 像这样:

前:

pom.xml
src
├── main
│   └── resources
│       ├── archetype-resources
│       │   └── pom.xml
│       ├── META-INF
│       │   └── maven
│       │       └── archetype-metadata.xml
│       ├── __rootArtifactId__.module1
│       │   ├── pom.xml
│       │   └── ...
│       ├── __rootArtifactId__.module2
│       │   ├── pom.xml
│       │   └── ...
│       ├── __rootArtifactId__.module3
│           ├── pom.xml
│           └── ...
│
└── test
    └── resources
        └── projects...

后:

pom.xml
src
├── main
│   └── resources
│       ├── archetype-resources
│       │   ├── pom.xml
│       │   ├── __rootArtifactId__.module1
│       │   │   ├── pom.xml
│       │   │   └── ...
│       │   ├── __rootArtifactId__.module2
│       │   │   ├── pom.xml
│       │   │   └── ...
│       │   └── __rootArtifactId__.module3
│       │       ├── pom.xml
│       │       └── ...
│       └── META-INF
│           └── maven
│               └── archetype-metadata.xml
└── test
    └── resources
        └── projects...

然后编辑对 archetype-metadata.xml 中模块的任何引用,删除“..”相对路径。

Maven Archetype JIRA 中也有类似的问题: https : //issues.apache.org/jira/browse/ARCHETYPE-422

在撰写本文时,它仍然是开放的。

为了获得我的项目的工作原型,我采用了 jboss-javaee6-webapp-ear-blank-archetype-7.1.3.CR1.jar 并使用它生成了一个项目。 由于我们使用的是 WebSphere,因此我修改了该项目以删除许多特定于 jboss 的项目。 在这些修改之后,我从项目运行创建:

mvn clean archetype:create-from-project -Dinteractive=true

我修改了 archetype.groupId 和 archetype.artifactId 以设置我希望原型在存储库中结束的位置及其名称。 我还修改了包值,但接受其他项目的默认值。

就像您所经历的那样,这似乎运行良好。 当我 cd 到 \\target\\generated-sources\\archetype 并运行 mvn install 时,会使用适当的路径和名称创建 jar 文件。

然后我使用 Eclipse 生成一个项目,这也很好用。 很棒,对吧?

因此,我针对我们的环境进行了一些小的更改,并使用相同的组和工件 ID 执行上述步骤。 然后我使用 Eclipse 生成一个项目,它给出了错误:

org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/pom.xml'

(我在 mvn archetype:generate 的命令行上并没有一直收到相同的错误,但我已经看到它发生了。)

出于某种原因,从项目创建时,再次运行这些步骤并输入不同的 archetype.artifactId 可以解决此问题。 当 m2e 不喜欢原型更新时,似乎有些东西会被破坏或改变。

无论如何,这可能值得一试。 我会看看我是否可以缩小问题的范围,但现在我将为每个更新使用唯一的 artifactIds。

该问题似乎仅在使用 Eclipse m2e插件时出现。 我能够使用以下命令行解决问题:

mvn archetype:generate

暂无
暂无

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

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