Create your own Maven2 Archetype

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:

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/
  • or

  • Define it in the plugin of the parent pom:


    and then simply use:
    mvn archetype:generate

About Pascal Alma

Pascal is a senior software developer and architect. Pascal has been designing and building applications since 2001. He is particularly interested in Open Source toolstack (Mule, Spring Framework, JBoss) and technologies like Web Services, SOA and Cloud technologies. Lately he is having great fun by building iOS apps with Swift. Specialties: JEE AWS XML/XSD/XSLT Web Services/SOA Mule ESB/ WSO2 ESB Maven Cloud Technology Swift/ iOS
This entry was posted in Maven and tagged , . Bookmark the permalink.

2 Responses to Create your own Maven2 Archetype

  1. Denis says:


    i’m also trying to create an archetype, but after using:

    mvn archetype:create-from-project -X

    i got this error: 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] ————————————————————————
    [INFO] ————————————————————————
    [INFO] : 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(
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(
    at org.apache.maven.DefaultMaven.doExecute(
    at org.apache.maven.DefaultMaven.execute(
    at org.apache.maven.cli.MavenCli.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.codehaus.classworlds.Launcher.launchEnhanced(
    at org.codehaus.classworlds.Launcher.launch(
    at org.codehaus.classworlds.Launcher.mainWithExitCode(
    at org.codehaus.classworlds.Launcher.main(
    Caused by: org.apache.maven.plugin.MojoFailureException: Cannot parse the POM by JDOM.
    at org.apache.maven.archetype.mojos.CreateArchetypeFromProjectMojo.execute(
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(

    • Pascal Alma says:

      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.

Comments are closed.