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

Enterprise resource management with JBoss Seam and Maven 2

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

EJBs project POM and file structure

Figure 2 is a breakdown of the internal structure of the EJB project folder.

The EJB project folder
Figure 2. The EJBs project folder (click to enlarge)

The resources directory has three very important files that are core to the EJB 3 mechanism, especially because Seam is now an integral part of the project architecture. Figure 3 illustrates the layout of the resources folder.

The layout of the resources folder
Figure 3. The layout of the resources folder (click to enlarge)

Note the explicit META-INF directory. Maven will not create this for you if it is missing (in case the EJB project structure was created manually, for instance), so it is recommended that Maven's archetype plugin be used to create Maven project types. All files in this directory will end up in the root of the JAR file.

In the ejb-jar.xml descriptor file, shown in Listing 6, the application attempts to bind Seam's Interceptor class to one or more EJB modules deployed within the EAR file. This means that we can have multiple EJB JARs deployed and packaged separately for functional reasons (perhaps the EJBs were produced from build systems other than Maven and are required in the current EAR, but Seam does not need to know about those modules) and removed from the Interceptor's list of modules to manage.

Listing 6. ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns=""

Seam's standard interceptor class, org.jboss.seam.ejb.SeamInterceptor, is declared in Listing 6. In the assembly descriptor, the * would indicate all packaged EJB modules. You would need to explicitly declare all EJB modules under the control of the interceptor. (It's a shame that you can't exclude EJB modules by name; the descriptor file would be a lot shorter.)

Listing 7 shows the persistence.xml file, which is really the application's gateway into the application server's data source configurations. You can see that Hibernate is the default persistence provider, with a reference to a configured data source (in the JBoss application server). The file is short, with no real reference to Seam-specific details.

Listing 7. persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns=""
   <persistence-unit name="userDatabase">
         <property name="" value="create-drop"/>

Note that is an empty file, but it needs to be present because Seam will not work without it.

Figure 4 is a look at the finally packaged ejbs.jar module.

The ejbs.jar module file structure
Figure 4. The ejbs.jar module file structure (click to enlarge)

And Listing 8 shows the pom file for the ejb-jar project.

Listing 8. pom.xml

   <name>enterprise java beans</name>

Note that the dependencies section was moved below the build configuration and tree-collapsed to help you better understand the maven-ejb-plugin configuration.

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