Wednesday Apr 10, 2013

Java EE 7 Maven Archetype

For those of us doing Java EE development with Maven (which by my own account as a former consultant is pretty much all Java EE/GlassFish adopters), Archetypes can be a great productivity boost, especially while getting started. You will be pleased to know that there is already a Java EE 7 Maven Archetype out there in the https://nexus.codehaus.org/content/repositories/snapshots/ repository (courtesy of GlassFish of course).

You can use it directly from the Maven command-line like so:

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes 
    -DarchetypeArtifactId=webapp-javaee7 
    -DarchetypeVersion=0.3-SNAPSHOT 
    -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/ 
    -DgroupId=your_group_id 
    -DartifactId=your_artifact_id 
    -Dversion=your_version
    -Dpackage=your_package
    -Darchetype.interactive=false 
    --batch-mode 
    --update-snapshots 
    archetype:generate

If you prefer NetBeans, you can do that too. Just define a new repository with the URL https://nexus.codehaus.org/content/repositories/snapshots/ under "Maven Repositories" on the "Services" tab. Then proceed to "New Project -> Maven -> Project from Archetype" and enter "webapp-javaee7" into the search box. Select the 0.1-SNAPSHOT and click "Finish".

Either way, once the project is generated, you can of course tweak the POM and source code to meet your needs. It should be pretty straightforward - give me a shout if you need help getting started. Happy hacking!