Sunday, July 03, 2011

Creating a Maven Web Application Archetype in NetBeans 7.0

Slide | The Seven Rules of Great Web Applicati...Image by quasarkitten via Flickr
The  basics for creating a Maven archetype can be found in the Maven - Guide to Creating Archetypes. The guide gives general guidelines for creating an archetype, but no specific details for web applications. This tutorial will show you a simple way of creating a web application archetype and using it. We will use NetBeans 7.0 to create our project, create the archetype, and consume it. This application uses JSF 2.x and GlassFish. However the principles are the same for web applications in general.

The first more practical approach is to create, or use an existing application, and convert it to an archetype.
  1. Create a new Maven web project in NetBeans.
  2. Modify the pom.xml to include the dependencies you require in the project.
  3. (Optional) Modify the pom.xml to include a license
  4. (Optional) Create a web.xml. This is not required for JEE6 web application generally. However, we need one for the Faces Servlet.
  5. (Optional) Add a resource file for externalizing message resources
  6. Create a basic web page, and supporting classes. JSF for example has the following.
    • Index.xhtml
    • is a Java EE 6 JSF @ManagedBean, and @RequestScoped bean. You could use @Named and @RequstScoped from CDI as well.
  7. Once you are satisfied withe the project, execute mvn archetype:create-from-project. This will create your new archetype in the target/generated-sources/ directory.
  8. Open the newly created project in NetBeans and make any necessary changes.
  9. Next execute mvn install. This will install your new archetype in the local repository.
  10. Create a new project using the new archetype, and run it.
Here is a link to the project: You can create the archetype from it.

I have created a Youtube video that demonstrates the process.

Enhanced by Zemanta


Rafael A P Nascimento said...

thank you, very good post!!

Popular Posts