Build the enterprise with EJB 3, JBoss Seam, and Maven 2

Enterprise resource management with JBoss Seam and Maven 2

JBoss Seam is the extension framework that made JSF a viable alternative to Struts, and Maven 2 is the build tool that convinced you to leave Ant for good. The problem is, these two cool tools don't play well together. Or do they? Agile consultant Michael Nyika shows you how to integrate Seam and Maven 2 in your enterprise development projects using EJB 3.

If you're using Apache Ant to create EJB 3-based EAR projects as a final artifact, you may find the configuration files complicated to set up. Ant introduces complexity to the process of integrating multiple resources from many locations, especially because there's no way to see what the targets are doing on first glance. Moreover, Ant targets are often grouped together in a hierarchy, so that certain targets are executed only when others are successful.

Maven 2 does a better job of modularizing the components that make up an EJB 3 project. From EAR configuration files to EJBs to WAR files, a well-known group of projects always represents the individual components to be used. Many developers view Maven 2 as too complicated, however, and stick with Ant even for complex enterprise projects where Maven is clearly the better choice. One of the most powerful features of Maven 2, resource placement, is also one of the least understood.

In this article we'll take a realistic, hands-on approach to learning about enterprise resource management with Maven 2. The example application, built on EJB 3, uses JSF for the presentation tier. The glue between the two frameworks is JBoss Seam, which facilitates smooth collaboration between EJB 3's resources (session beans and entity beans) and JSF's (managed beans and JSF views). In addition to learning the basics of enterprise resource placement in Maven 2, you'll learn where Seam-specific resources fit into Maven's seemingly rigid structuring of project archetypes (JAR, WAR, POM, EAR, EJB, and so on).

Development environment and prerequisites

To develop the example application I used JDK 1.6 update 4 with JBoss Seam version 2.0.1 and Apache Maven version 2.0.8. My development platform is Linux OpenSuSE 10.3 and my JBoss Application Server is at version 4.2.2. To facilitate easier access to binary executables such as mvn,, and so on, I set environment variables such as $JBOSS_HOME and $JAVA_HOME on localhost.

This article requires some knowledge of JSF and using Maven as a build tool. You don't need to know how JBoss Seam works to follow along, but you should be familiar with EJB concepts.

The example application

The example application for this article simulates a screen in which a user new to an arbitrary Web site registers three simple bits of information: a formal username, his or her full name, and the password to be associated with the username. Seam is important in this example because it uses a plain old Java object (the POJO used to hold the user's information) implicitly from within EJB's stateless session bean. Unlike JSF applications where Seam is absent, there is no need in the sample application to explicitly reference the POJO as a managed bean (which would in turn need to obtain a reference to the stateless bean that handles the actual user registration).

Figure 1 shows an overall view of the Maven project as seen from a filesystem explorer window. It shows the overall directory structure, including the parent POM project.

Overall view of the Maven project
Figure 1. Overall view of the Maven project (click to enlarge)

The different elements composing the project structure break down as follows:

  • The EAR directory represents the enterprise archive Maven project containing all EAR packaging information, as well as the elements of the artifact that will ultimately be deployed. It should not be confused with the parent directory (the directory that will contain projects that will be eventually packaged up within the EAR file). The EAR project is just another project as far as the parent project is concerned.

  • The EJBs directory is a directory representing the application-specific location where Enterprise JavaBeans live.

  • The servlets directory is a special Maven project that is a container for (potentially) multiple Web application archives bundled up in the single EAR file. We'll examine this later, and see that its pom configuration is similar in type to the parent pom configuration.

  • The jboss-seam directory represents the JBoss Seam EJB project. This project was built from a part of the JBoss Seam source download. I'll explain this project in more detail later in the article.

1 2 3 4 5 6 7 Page 1
Page 1 of 7