Creating a Maven archetype from an existing project with NetBeans is very easy.
Table of Contents
- Take your existing project to use as a template. This is the project as it will be created.
- In NetBeans right click on your project template name, choose
Custom > Goals..., write in the
archetype:create-from-projectgoal and finally click
OK. Otherwise at your project template pom directory you may also run:
- Now you can find the generated archetype in the
target/generated-sources/directory. Such an archetype is a Maven project itself but with the packaging type:
- Open the generated archetype (double click on the generated archetype name) and edit the pom accordingly your specific needs: don’t accept the pom automatically generated without having a look at it.
- Once it’s all ok you have to install the archetype in your local Maven repository,
mvn clean install.
- Create an archetypes catalog in your Maven local repository by running
mvn archetype:crawl. Make sure your IDE is aware of the newly created archetype forcing a re-indexing of your Maven local repository.
- Finally test your archetype by creating a new project.
From the NetBeans IDE right click on the Project window and choose
New Project... > Maven > Project from Archetype, then select your archetype from the ones listed; or at command line simply run
mvn archetype:generate -DarchetypeCatalog=local.