安装使用 mvn archetype:create-from-project 创建的多模块原型时出错 [英] Error installing a multimodule archetype created with mvn archetype:create-from-project

查看:167
本文介绍了安装使用 mvn archetype:create-from-project 创建的多模块原型时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a project with the following structure:

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

project (pom)
project-client (module, jar)
project-ejb (module, jar)
project-web (module, war)
project-ear (module, ear)

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

Inside the pom the modules reference the parent using:

<relativePath>../project</relativePath>

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

And the root pom references the modules the same way (using ../).

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

I can create an archetype using archetype:create-from-project, and everything runs smoothly.

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

But when I try to install the archetype (mvn install inside the target/generated-sources/archetype dir), I get the error:

    [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 没有成功.有什么线索吗?

The problem is that the file exists (it's on target/generated-sources/archetype/src/main/resources/__rootArtifactId__client/pom.xml), and I tried to fiddle with the archetype-metadata.xml with no success. Any clues?

提前致谢

推荐答案

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

It looks like the archetype plugin doesn't support flat layout for multi-module projects. If that is your case a workaround is to change to a nested layout. I did it by moving the modules outside the archetype-resources directory into it. Like this:

之前:

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 中模块的任何引用,删除.."相对路径.

And then you edit any reference to the modules in archetype-metadata.xml, removing the '..' relative path.

这篇关于安装使用 mvn archetype:create-from-project 创建的多模块原型时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆