Error installing a multimodule archetype created with mvn archetype:create-from-project
Asked Answered
C

3

6

I have a project with the following structure:

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

Inside the pom the modules reference the parent using:

<relativePath>../project</relativePath>

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

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

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

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?

Thanks in advance

Chancre answered 22/12, 2011 at 20:11 Comment(1)
Same problem for me. Any clues ?Peccadillo
L
3

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:

Before:

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...

After:

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...

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

Lingwood answered 16/12, 2013 at 4:30 Comment(0)
B
2

There is a similar issue to this in the Maven Archetype JIRA: https://issues.apache.org/jira/browse/ARCHETYPE-422

As of this writing, it remains open.

In order to get a working archetype for my project, I have taken jboss-javaee6-webapp-ear-blank-archetype-7.1.3.CR1.jar and generated a project using it. I then modified the project to remove many of the jboss specific items since we are using WebSphere. After these modifications, I run the create from project:

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

I modify the archetype.groupId and archetype.artifactId to set the location I want the archetype to end up in the repository and its name. I also modify the package value but accept the defaults for the other items.

Much like you experienced this seems to run fine. When I cd to \target\generated-sources\archetype and run mvn install, the jar file is created with the appropriate path and name.

I then use Eclipse to generate a project, and this works fine as well. Great, right?

So I make some small changes to be more specific to our environment, and run through the above steps using the same group and artifact IDs. I then use Eclipse to generate a project, and it gives the error:

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

(I do not consistently get the same error on the command line for mvn archetype:generate, but I have seen it occur.)

For some reason, running through the steps again and entering a different archetype.artifactId, when creating from project, resolves this issue. There appears to be something that gets corrupted or changed when the archetype is getting updated that m2e does not like.

Anyway, this might be worth giving a try. I will see if I can narrow down the issue, but for now I will be using unique artifactIds for each update.

Banlieue answered 22/3, 2013 at 19:49 Comment(0)
G
-1

The problem appears to occur only when using the Eclipse m2e plugin. I was able to solve the problem using the following command line:

mvn archetype:generate
Gabriello answered 23/10, 2013 at 2:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.