Friday, March 4, 2011

Maven Archetype Usage with SVN

I've been creating Maven2 archetypes for use with projects involving Spring3 and JBoss AS 5.1. They are not trivial to configure, so creating a reusable archetype improves developer efficiency. The archetypes are hosted on google code. Go here to get the URL needed for accessing them: https://code.google.com/p/clear-maven-archetypes/source/checkout (no, I haven't added to a regular maven repository nor do I intend to).

An archetype is just another maven project so installing a new one and using it is simple. The name of the archetype for this example is "shellJBoss-archetype".

[This is all geared to Eclipse, so you need m2eclipse installed and subclipse for working with SVN]

You need to checkout "shellJBoss-archetype" from the trunk. You will need to add a new location to your repositories; namely,
https://clear-maven-archetypes.googlecode.com/svn/trunk.

Once you have done this, explore the new trunk and you will see the projects below. You need to right-click "shellJBoss-archetype" and choose "checkout..."




This creates a new Eclipse project for you called"shellJBoss-archetype". Switch to a Java development perspective in Eclipse. Now you need to add the new archetype to your local repository. Right-click the new project and choose "Run As". Choose "Maven Install" and that will do it for you.




You will notice in the console output this key line just before Build Success:

[INFO] --- maven-archetype-plugin:2.0:update-local-catalog (default-update-local-catalog) @ shellJBoss-archetype ---

The "shellJBoss-archetype" is now usable by the Maven new project wizard. Choose File:New:Other:Maven Project. As you work through the wizard you will get to the archetype selection screen. Choose the "Default Local" catalog and you will see the new archetype.



Critical Step
Maven does some stupid text find/replace operations that can really mess a project up. You need to set version equal to 1.0 as shown below when using the wizard. If you don't, your XML files will all be invalid.


After you have made the project, you can go into the POM.xml file and change the version to whatever you like. Also note that the archetype will name your new project and the resulting deployment *.war file using the artifactId you specify in the wizard. You can also change this in POM.xml if you like.

After you create your project, take a look and see what is in it. There are sample files showing a simple webflow with spring security and some tests written using TestNG. In fact, the project is ready to deploy to JBoss AS 5.1 (using the maven command "jboss:hard-deploy").


Selecting "Maven Build..." lets you type in whatever maven goal (command) you want. Assuming a default JBoss install, go to this url (but using your artifactId) to see the project in action:

http://localhost:8080/your-artifactId


No comments:

Post a Comment

Thanks for your feedback!