New maven archetype from project


Create a maven archetype from an existing maven project structure


This recipe details the basic steps one needs to perform in order to create a maven archetype from an existing project to speed up future developments.

How to

The following are the necessary steps for the creation of the archetype (we assume you already have a project with the necessary structure):

  1. cd $project_home – go to your project root folder
  2. mvn clean – make sure you start with a fresh build
  3. mvn archetype:create-from-project – execute the create-from-project goal of the archetype plugin in order to generate the archetype sources in $project_home/target/generated-sources/archetype
  4. cd target/generated-sources/archetype – go to the archetype generated sources
  5. mvn clean install – install the project in your local maven repository

To test the archetype you just created, try to create a new project from an existing archetype, by executing mvn archetype:generate, select the archetype from the coordinates you have specified for your original project, fill in the groupId, artifactId, version, package and you should be able to have a new fresh project with the same structure of your original project.


When I implement a new project, it’s very common to start by looking at existing maven archetypes and trying to choose one that fits well my technical needs. However, in all of them I end up doing several changes that I rarely remember to share with myself for similar projects in the future. So, for new projects, I have to repeat the process, once again. In order to avoid that, I have created this recipe as a reminder for myself (and hopefully, others as well!) to create an archetype when you think the project is more or less in a stable version.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s