Image by quasarkitten via FlickrThe 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.
- Create a new Maven web project in NetBeans.
- Modify the
pom.xmlto include the dependencies you require in the project.
- (Optional) Modify the
pom.xmlto include a license
- (Optional) Create a
web.xml. This is not required for JEE6 web application generally. However, we need one for the Faces Servlet.
- (Optional) Add a resource file for externalizing message resources
- Create a basic web page, and supporting classes. JSF for example has the following.
IndexBean.javais a Java EE 6 JSF
@RequestScopedbean. You could use
@RequstScopedfrom CDI as well.
- Once you are satisfied withe the project, execute
mvn archetype:create-from-project. This will create your new archetype in the
- Open the newly created project in NetBeans and make any necessary changes.
- Next execute
mvn install. This will install your new archetype in the local repository.
- Create a new project using the new archetype, and run it.
I have created a Youtube video that demonstrates the process.