| 30 September 2009 |
Although I am using Maven for quite some time now over the last years I have never had the need to create my own archetype. Untill my current project. And luckily this is greatly simplified in Maven2.2.
The first thing to do is to create your 'base' module that you want to use as template for your other modules. When this is in place you simply go to the root of your base module and enter:
mvn archetype:create-from-project
After this has successfully completed you go to the directory 'target/generated-sources/archetype' and enter the command:
mvn install
And after that you can add the archetype to the catalog in your local repository with the command:
mvn deploy
In our project we are working with Artifactory as repository manager, so the next step is to add the archetype catalog to this repository so the rest of the team can use it too. Unfortunately this isn't a standard feature (yet) in Artifactory so you will need to perform the following steps to achieve this:
- Go to the directory in which the local archetype catalog can be found (something like /Users/name/.m2/ on the Mac)
- Perform the command
curl -u username:password -f -d @archetype-catalog.xml -X PUT "http://artifactory-server:8888/artifactory/libs-releases-local/archetype-catalog.xml"
Here username and password are the credentials you use to login to your Artifactory instance
Now the archetype is ready to be used. To make use of it you can either:
- Add the catalog to use as parameter in the command:
mvn archetype:generate -DarchetypeCatalog=http://artifactory-server:8888/artifactory/libs-releases-local/ -
Define it in the plugin of the parent pom:
XML:
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-archetype-plugin</artifactId>
-
<version>2.0-alpha-4</version>
-
<configuration>
-
<archetypeCatalog>http://artifactory-server:8888/artifactory/libs-releases-local/</archetypeCatalog>
-
</configuration>
-
</plugin>
and then simply use:
mvn archetype:generate -
or


2 comments to 'Create your own Maven2 Archetype'
6 January 2010
Pascal,
i'm also trying to create an archetype, but after using:
mvn archetype:create-from-project -X
i got this error: java.io.IOException: Cannot parse the POM by JDOM
The full stacktrace in debug mode is in the end of this comment.
It proccess all nodes indicated through my parent pom recursively, and ends abrupt with this message.
Do you have any idea wich can cause it?
Thks, Denis
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] : java.io.IOException: Cannot parse the POM by JDOM.
Cannot parse the POM by JDOM.
Cannot parse the POM by JDOM.
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.BuildFailureException: Cannot parse the POM by JDOM.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:579)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:227)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
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:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoFailureException: Cannot parse the POM by JDOM.
at org.apache.maven.archetype.mojos.CreateArchetypeFromProjectMojo.execute(CreateArchetypeFromProjectMojo.java:207)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
6 January 2010
Hi Denis,
I haven't seen this exception before. It appears that something in your pom.xml is invalid xml, like strange characters or a space at some invalid place, could also be in one of the parent poms. Perhaps you can comment out parts of the pom.xml to determine the exact line that causes the exception.
HTH.