I have created a lot of small applications that include spring and acegi. Most of the time I copy most of the resources from another project. Some time ago I learned about the maven archetypes. An easy way to create the project structure. That was the time I decided that I wanted to have my acegi springframework archetype. Last weeks I found some time to create this archetype. You can download the files here:
http://code.google.com/p/gridshore/
And the generated maven site here:
http://www.gridshore.nl/projects/springframeworkarchetype/index.html
Ofcourse there is also a maven website about creating an archetype, this is not a very extensive website. In this blog item I will explain more about the archetype I created.
First thing to know, well surprise, the archetype is just a maven project. You can start you new archetype by using a
maven archetype:
mvn archetype:create
-DgroupId=nl.gridshore.samples.archetype
-DartifactId=SpringframeworkArchetype
-DarchetypeArtifactId=maven-archetype-quickstart
Have a look at the pom for the other properties; scm, distributionManagement, etc.
The project itself contains an src\main\resources\META-INF\maven\archetype.xml file that defines all the resources that need to be copied.
<archetype>
<id>SpringframeworkArchetype</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
<resources>
<resource>src/main/webapp/index.jsp</resource>
<resource>src/main/webapp/WEB-INF/web.xml</resource>
<resource>src/main/webapp/WEB-INF/action-servlet.xml</resource>
<resource>src/main/webapp/WEB-INF/jsps/welcome.jsp</resource>
<resource>src/main/webapp/WEB-INF/jsps/adminwelcome.jsp</resource>
<resource>src/main/webapp/WEB-INF/jsps/accessdenied.jsp</resource>
<resource>src/main/webapp/WEB-INF/jsps/login.jsp</resource>
<resource>src/main/webapp/WEB-INF/jsps/loginerror.jsp</resource>
<resource>src/main/resources/security-springConfig.xml</resource>
<resource>src/main/resources/views.properties</resource>
<resource>src/main/resources/errormessages.properties</resource>
<resource>src/main/resources/sitetext.properties</resource>
<resource>src/main/resources/log4j.dtd</resource>
<resource>src/main/resources/log4j.xml</resource>
</resources>
</archetype>
The structure is pretty easy, you can find all the resources under the directory:
src\main\resources\archetype-resources
You can use the following parameters in your file as placeholders:
http://maven.apache.org/plugins/maven-archetype-plugin/create-mojo.html. Have a look at the src\main\resources\archetype-resources\pom.xml for an example:
<groupId>$groupId</groupId>
<artifactId>$artifactId</artifactId>
<version>$version</version>
Hope that helps you on your way to your own archetype. If you just want to use mine:
mvn install
mvn archetype:create
-DgroupId=your.groupid
-DartifactId=your.artifactId
-DarchetypeArtifactId=SpringframeworkArchetype
-DarchetypeGroupId=nl.gridshore.samples.archetype
-DarchetypeVersion=1.0.0-SNAPSHOT