Error installing multimodal archetype created using mvn archetype: create-from-project

I have a project with the following structure:

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

Inside pom, the modules reference the parent using:

<relativePath>../project</relativePath> 

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

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

But when I try to install the archetype (installing mvn inside the target / generate-sources / archetype file), I get an error message:

  [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 is located in the target / generated-sources / archetype / src / main / resources / __ rootArtifactId__client / pom.xml file), and I tried not to understand the archetype-metadata.xml file without success. Any clues?

Thank you in advance

+4
source share
3 answers

The archetype plugin does not seem to support a flat layout for multi-module projects. If this is your case, a workaround is to switch to a nested layout. I did this by moving 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... 

Then you edit any module reference in the archetype-metadata.xml file, removing the relative path "..".

+1
source

There is a similar problem in the Maven Archetype JIRA: http://jira.codehaus.org/browse/ARCHETYPE-422

At the time of this writing, it remains open.

To get a working archetype for my project, I took jboss-javaee6-webapp-ear-blank-archetype-7.1.3.CR1.jar and created a project using it. Then I changed the project to remove many jboss elements as we use WebSphere. After these changes, I start the creation from the project:

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

I modify archetype.groupId and archetype.artifactId to set the location where I want the archetype to appear in the repository and its name. I also change the value of the package, but accept the default values ​​for other elements.

Like you, it looks like everything is working fine. When I connect to the \ target \ generated sources \ archetype and run mvn install, the jar file is created with the appropriate path and name.

Then I use Eclipse to create the project, and it works fine. Great, right?

Therefore, I make some small changes more specific to our environment and follow the steps described above using the same group and artifact identifiers. Then I use Eclipse to generate the project, and it gives an error:

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

(I do not always get the same error on the command line for mvn archetype: generate, but I saw how this happens.)

For some reason, re-executing the steps and entering another archetype.artifactId file when creating from a project fixes this problem. It seems that something is damaged or changed when the archetype is updated, and m2e does not like it.

In any case, it might be worth a try. I will see if I can narrow down the problem, but for now I will use unique artifacts for each update.

0
source

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

 mvn archetype:generate 
0
source

Source: https://habr.com/ru/post/1387634/


All Articles