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

Getting started

Let's dive into the first section of the project structure, the project POM file, which is shown in Listing 1.

Listing 1. Parent project POM file

<project>

   <modelVersion>4.0.0</modelVersion>
   <groupId>root</groupId>
   <version>1.0</version>
   <artifactId>project</artifactId>
   <packaging>pom</packaging>
   <name>project</name>
   <modules>
      <module>servlets</module>
      <module>ejbs</module>
      <module>jboss-seam</module>
      <module>ear</module>
   </modules>
   <dependencyManagement>
      <dependencies>
        <dependency>
            <groupId>root.project.servlets</groupId>
            <artifactId>servlet</artifactId>
            <version>1.0</version>
            <type>war</type>
         </dependency>
         <dependency>
            <groupId>root.project</groupId>
            <artifactId>ejbs</artifactId>
            <version>1.0</version>
            <type>ejb</type>
         </dependency>
    <dependency>
            <groupId>root.project</groupId>
            <artifactId>jboss-seam</artifactId>
            <version>2.0</version>
            <type>ejb</type>
         </dependency>
      </dependencies>
   </dependencyManagement>
</project>

First off, you'll note that the project packaging type is pom. Multiple modules are also listed here that correspond directly to the directories (projects) seen in Figure 1. The dependency management section is particularly helpful because it lists the exact nature of the elements that compose the modules listed here, not the modules themselves.

Take a look at the first dependency in the dependency management section, the servlet artifact. The groupId may be confusing at first. It gets its appropriate value first from the parent project's groupId (<groupId>root</groupId>), then from the artifactId (<artifactId>project</artifactId>), and finally from the name of the parent project that houses all possible Web servlet projects (servlets, in this case). The groupId would seem to be a pointer to the project that would house this particular Web application artifact, hence <groupId>root.project.servlets</groupId>.

Because the root context of any Web application must be unique (among all others within a running Web container), the artifactId will vary accordingly, if the version number is the same for all Web projects. This assumes that the POM files for the individual Web projects do not have a <finalName> configuration within the default <build> section of the configuration file. The servlets module is, of course, packaged as a WAR file, hence the war packaging.

The EJB and jboss-seam projects are both deployed as EJBs (hence the packaging ejb); again, the groupIds seem to be pointers, from the parent project's perspective, to the location of the EJB and Seam directories excluding the directory names, hence <groupId>root.project</groupId>. The Seam project has a version number of 2.0 simply because we are dealing with JBoss Seam's Candidate Release version 2.0.1.

EAR project POM file and file structure

Listing 2 offers a quick glance into the POM file for the EAR project.

Listing 2. EAR project POM file

<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>

In the dependencies section, all three dependencies listed in the parent project's pom section are also found here in the exact same manner, with the exception of the JBoss Expression Language JAR dependency. There is a slight change in a dependency property: instead of packaging, we find type, with the same values (ejb, war, and now jar).

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