Creating a Weld Project using Maven and NetBeans
David Salter, 15th January 2010
Now that the Beta Maven archetypes for Weld (the reference implementation of JSR 299 - Java Contexts and Dependency Injection) have been published in the Maven Central Repository, its easy to create Weld projects using Maven and NetBeans.
Assuming you have NetBeans 6.8 set up with GlassFish v3 server and the Maven plugin, use the following steps to create a new project.
1. Create a new Maven project.
Select "File | New Project" and then choose Maven as the category and "Maven Project" as the project type.
2. Add the Weld Maven Archetypes
On the Maven Archetype screen, press the "Add..." button. This will cause the "Specify archetype details" screen to be displayed. On this screen we can add details of the different Maven archetypes that are currently available for Weld.
There are currently 3 Maven archetypes defined in the catalog.
weld-jsf-servlet-minimal - Weld archetype for creating an application using JSF 2.0 and CDI 1.0 for Servlet Containers (Tomcat 6 / Jetty 6)
weld-jsf-jee-minimal - Weld archetype for creating a minimal Java EE 6 application using JSF 2.0, CDI 1.0 and EJB 3.1 (persistence unit not included)
weld-jsf-jee - Weld archetype for creating a Java EE 6 application using JSF 2.0, CDI 1.0, EJB 3.1 and JPA 2.0 (persistence unit included)
For this example, I'm using weld-jsf-servlet-minimal. Enter the details of the archetype from the catalog into the dialog and press "OK".
On the following screen, select the archetype you've just added and press the "Next" button.
3. Select Project Details
On the final page of the create project wizard, enter the project name, location and base package name for the project and press the "Finish" button.
4. Run the project
Now that we've created a sample project, it can easily be executed by right clicking on the project node and selecting the "Run" option. This will open a dialog asking for the default deployment server - select a GlassFish v3 server and press "OK".
If all is successful, the project should now build and be opened in the default browser.
Originally published at http://www.davidsalter.co.uk
You can discuss this article here.