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 3
Page 3 of 7

Further down, the configuration of the maven-ear-plugin is key, as you can see in Listing 3.

Listing 3. Configuring the maven-ear-plugin

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>root.project</groupId>
   <artifactId>ear</artifactId>
   <packaging>ear</packaging>
   <version>1.0</version>
   <name>ear assembly</name>
   <dependencies>
      <dependency>
         <groupId>root.project</groupId>
         <artifactId>ejbs</artifactId>
         <type>ejb</type>
    <version>1.0</version>
      </dependency>
      <dependency>
         <groupId>root.project.servlets</groupId>
         <artifactId>servlet</artifactId>
         <type>war</type>
    <version>1.0</version>
      </dependency>
    <dependency>
         <groupId>root.project</groupId>
         <artifactId>jboss-seam</artifactId>
     <version>2.0</version>
         <type>ejb</type>
      </dependency>
     <dependency>
         <groupId>jboss</groupId>
         <artifactId>jboss-el</artifactId>
     <version>2.0</version>
         <type>jar</type>
      </dependency>
   </dependencies>
   <build>
      <plugins>
         <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
        <applicationXml>${artifactId}/src/main/resources/application.xml</applicationXml>
        <jboss>${artifactId}/src/main/resources/jboss-app.xml</jboss>
        <defaultLibBundleDir>lib</defaultLibBundleDir>
               <archive>
                  <manifest>
                     <addClasspath>true</addClasspath>
                  </manifest>
               </archive>
        <modules>
        <ejbModule>
               <groupId>root.project</groupId>
            <artifactId>ejbs</artifactId>
                </ejbModule>
        <ejbModule>
               <groupId>root.project</groupId>
            <artifactId>jboss-seam</artifactId>
                </ejbModule>
        <webModule>
               <groupId>root.project.servlets</groupId>
            <artifactId>servlet</artifactId>
               <contextRoot>/servlet</contextRoot>
             </webModule>
        </modules>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

The standard J2EE EAR deployment file, application.xml, is located at ${artifactId}/src/main/resources/application.xml, which in our scenario translates to ear/src/main/resources/application.xml. Similarly, jboss-app.xml, a JBoss Application Server-specific file, is located here at ear/src/main/resources/jboss-app.xml. The defaultLibBundleDir's value of lib refers to the name of the directory in which all JARs not already packaged into the WAR file (or files) will be held.

The rest of the file lists the various EJB and WAR file projects in the plugin's specific format. Note that the context root of the single existing Web application, servlet, is /servlet.

Listing 4 looks into the application.xml EJB configuration file.

Listing 4. application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
             version="5">
    <display-name>Seam Registration</display-name>
    <module>
        <web>
            <web-uri>servlet-1.0.war</web-uri>
            <context-root>/servlet-1.0</context-root>
        </web>
    </module>
    <module>
        <ejb>ejbs-1.0.jar</ejb>
    </module>
    <module>
        <ejb>jboss-seam-2.0.jar</ejb>
    </module>
   </application>

The Web module entries (with context root value), ejbs-1.0.jar and Seam JARs, both deployed as EJBs, are now familiar. The display name, Seam Registration, is specific to the packaged example that you'll see later, but this name should really represent the name of the application in general.

Listing 5 shows the jboss-app.xml configuration file.

Listing 5. jboss-app.xml

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE jboss-app
    PUBLIC "-//JBoss//DTD J2EE Application 4.2//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd">
<jboss-app>
      <loader-repository>
      seam.jboss.org:loader=servlet-1.0
      </loader-repository>
</jboss-app>

This file is very short but contains information essential to making JBoss Seam work. It is a JBoss-specific file that configures the final artifact type, the EAR file, for JBoss deployment. A loader-repository entry of seam.jboss.org:loader=servlet-1.0 refers to the packaged WAR file as the repository for Seam resources. This entry can be placed in the maven-ear-plugin configuration in the EAR pom file.

Note that seam.jboss.org is a Seam-specific classloader. It acts as a way for Seam to disassociate artifacts bundled with the application from those that exist within the JBoss application server's shared artifacts or JARs (for example, those that reside in the default server's lib directory or in JBoss's general lib directory). Also note that the repository may just as well have been a reference to the ear-1.0.ear file as to the larger containing artifact.

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