Creating custom maven archetype
Maven provides many archetypes to generate various types of project skeletons. This blog post explains how to create a custom archetype that is tailor-made for your own situation. We will create an archetype for the Struts2 application.
My current development environment includes:
- Mac OS X 10.6.4
- Maven 2.2.1
- Java 1.6.0_20
Create your skeleton project
You need to have a starter project from which new archetype can be created. We can start with the Struts2 application created in the blog post Starting Struts2 web application development (using Maven2 and Eclipse)  to create a custom archetype for Struts2 based applications. You can download the zipped source code for this project here .
Generate your archetype
Go to your project directory (where pom.xml is) and run
The previous step creates the archetype in
Install the archetype locally
The new archetype can easily be installed in your local maven repository by running
mvn install in the
This step creates a metadata file called
archetype-catalog.xml under your local maven repository directory.
Use this new archetype to create new Struts2 project
Now, you are ready to use this archetype using
mvn archetype:generate command. Useto use your local repository instead of getting all the archetypes from the maven central repository.
The above command generates the following tree structure.
The following screen shot shows that the
struts.xmlreflects the new package structure for the
Test your new application
At this point you are ready to test your new Struts2 application.
mvn jetty:run from your new project directory.
And then in the browser, try these sample URLs to test the application:
Hello World: http://localhost:8080/hello/hello.action
Hello World with the twist: http://localhost:8080/hello/hello.action?name=New%20John%20Doe&zip=02451&age=40&gender=M