Loreno Oliveira
Loreno Oliveira

Reputation: 357

Cannot create archetype from existing maven project

I'm trying to create an archetype from an existing multi module maven project. For this, I change the directory to the root directory (where the root pom.xml is in) and issue a "mvn archetype:create-from-project". The build doesn't finish and I get the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project (default-cli) on project siaci-d: charsetName -> [Help 1]

Running again with the -e and -X flags I can see the following stack trace:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project (default-cli) on project siaci-d: charsetName
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
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:320)
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:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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.MojoFailureException: charsetName
at org.apache.maven.archetype.mojos.CreateArchetypeFromProjectMojo.execute(CreateArchetypeFromProjectMojo.java:285)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more

I checked the maven-archetype-plugin documentation and didn't find any reference to a charsetName attribute. So, I'm a bit lost about how to fix this. I'm using maven 3.0.4 with java 1.6.0_25 on a Ubuntu box. Any advice?

Any idea of what is going wrong here?

Upvotes: 2

Views: 3446

Answers (2)

s_bighead
s_bighead

Reputation: 1092

I was dealing with the same error then I found out what was messing up the archetype creation... First, I chose the encoding ISO-8859-1 by inserting the properties below on pom.xml:

<properties>
    <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
    <project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
    <project.resources.sourceEncoding>${project.build.sourceEncoding}</project.resources.sourceEncoding>
</properties>

Afterwards, I inserted the archetype-plugin with all configurations below at the build section of pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-archetype-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <defaultEncoding>${project.build.sourceEncoding}</defaultEncoding>
        <encoding>${project.build.sourceEncoding}</encoding>
        <archetypeArtifactId>archetype-wsjpa</archetypeArtifactId>
        <archetypeGroupId>br.com.example</archetypeGroupId>
        <archetypeVersion>1.0</archetypeVersion>
        <archetypeFilteredExtentions>java,xml</archetypeFilteredExtentions>
    </configuration>
</plugin>

By doing so, you should provide all archetype generation configuration in your own pom.xml instead of writing a property file (archetype.properties) to declare this configuration.

And finally, I ran maven with mvn clean install then mvn archetype:create-from-project -e -X

Even so, you still may notice some encoding errors like the one reported in this post, even if you have updated your pom.xml as shown above... If you're still having the same error after setting the correct encoding for your project, try to figure out which project file still contains invalid characters. To find the troublemaker file you should observe the debug lines that Maven shows on the console like this one: "[DEBUG] InputFileName:src\main\resources\META-INF\persistence.xml" and check which project files has been written to the folder ${basedir}\target\generated-sources\archetype\src\main\resources\archetype-resources. When encoding errors occurs during archetype creation, the aforementioned folder doesn't match the original project contents and it happens because Maven couldn't copy some resources due to invalid or incompatible characters which is not contained in the property specified charset.

Upvotes: 2

mauriciovigolo
mauriciovigolo

Reputation: 306

You posted this question some time ago, however this answer may help others.

I had the same problem in a project. This error happens when you have a file in your project that contains characters in a different encondig. A solution to this problem is replacing this characters — if it's not many, generate the archetype, revert the characters to the original and at last, change to the right enconding at the archetype metadata file.

Another option is to change the default enconding UTF-8 in the archetype generation, like this:

mvn archetype:create-from-project -Darchetype.properties=../archetype.properties 

For more information, follow this guides:

Upvotes: 4

Related Questions