Monday, February 22, 2010

Generate Maven2 Archetype from existing project

It's not hard to create custom archetype in Maven 2.2 from existing project. I had multi-module .ear Maven project which I want to reuse. So, I decided to play a little with custom archetypes to create my own and don't repeat myself again and again. Fixing dependencies manually - is not the best way to spend lifetime :)

To jumpstart archetype creaton there is a special maven goal of archetype plugin archetype:create-from-project. So,

mvn clean archetype:create-from-project
Now we have prototype of our archetype in target\generated-sources\archetype\ directory.
Then...

cd target\generated-sources\archetype\
mvn install
Friendly speaking, I had to do some tweaking to successfully generate normal .ear Maven 2 project which can be compiled and run without problems. It was fixing some of dependencies at Logic and EAR modules, bit it was not hard - just specifying ${groupId} where necessary. To use this archetype after "mvn install" just type

mvn archetype:generate
and choose EnterpriseApp-archetype from the list. It will looks like....
2: local -> EnterpriseApp-archetype (EnterpriseApp-archetype)
....
in the list.

Source code is here : http://ostas-blog-src.googlecode.com/svn/trunk/JbossCargoJpaEjbWebEarArchetype/.

To build it use
svn co http://ostas-blog-src.googlecode.com/svn/trunk/JbossCargoJpaEjbWebEarArchetype/

mvn install
You'll need to specify your jboss home location at parent pom.xml file to use cargo-jboss deployment. In my case it is


<jboss.home>C:/server/Java/jboss-4.2.2.GA/</jboss.home>

If you have any comments/issues/suggestions give me to know.