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.
- Create a new Maven web project in NetBeans.
- Modify the
pom.xml
to include the dependencies you require in the project. - (Optional) Modify the
pom.xml
to 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.
Index.xhtml
IndexBean.java
is a Java EE 6 JSF@ManagedBean
, and@RequestScoped
bean. You could use@Named
and@RequstScoped
from CDI as well.
- Once you are satisfied withe the project, execute
mvn archetype:create-from-project
. This will create your new archetype in thetarget/generated-sources/
directory. - 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.
1 comments :
thank you, very good post!!
Post a Comment