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

JBoss Seam (core source) POM and file structure

Our Maven project is based on the Registration example that comes with Seam's 2.0.1CR1 download. The core source files were extracted, compiled, and packaged as an EJB. Apart from the large number of source files, the remainder of the project structure features only a few more configuration files. Figure 5 offers an overall view.

Seam project structure
Figure 5. Seam project structure (click to enlarge)

You'll note that this looks similar to the EJBs project structure. The components.xml file in the resources/META-INF directory, shown in Listing 9, contains nothing more than a listing of all Seam-specific components that will be included (and loaded) as part of the framework.

Listing 9. components.xml

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
  <import>org.jboss.seam.core</import>
  <import>org.jboss.seam.transaction</import>
  <import>org.jboss.seam.framework</import>
  <import>org.jboss.seam.web</import>
  <import>org.jboss.seam.faces</import>
  <import>org.jboss.seam.international</import>
  <import>org.jboss.seam.theme</import>
  <import>org.jboss.seam.pageflow</import>
  <import>org.jboss.seam.bpm</import>
  <import>org.jboss.seam.jms</import>
  <import>org.jboss.seam.mail</import>
  <import>org.jboss.seam.security</import>
  <import>org.jboss.seam.captcha</import>
</components>

ejb-jar.xml in this Seam project is actually a file with the entry <ejb-jar></ejb-jar> and nothing more. Because this is the project that will provide Seam components to the rest of the structure, it needs no entries.

One of the more interesting files is faces-config.xml, shown in Listing 10. One point that might strike your is that this is a file that ordinarily appears within a Web project -- specifically, in the WEB-INF directory. You'd also expect the Seam-specific entries within it to be configured by the developer within the application-specific JSF faces-config.xml file. Actually, both of these statements are true, but with a special caveat. This particular file contains the default components Seam will use at system startup -- navigation handlers, view handlers, phase listeners, and so on.

Listing 10. faces-config.xml

<?xml version="1.0"?>
<faces-config version="1.2"
              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/web-facesconfig_1_2.xsd">
   <factory>
      <application-factory>org.jboss.seam.jsf.SeamApplicationFactory</application-factory>
   </factory>
   <application>
      <navigation-handler>org.jboss.seam.jsf.SeamNavigationHandler</navigation-handler>
      <view-handler>org.jboss.seam.jsf.SeamViewHandler</view-handler>
      <state-manager>org.jboss.seam.jsf.SeamStateManager</state-manager>
      <el-resolver>org.jboss.seam.el.SeamELResolver</el-resolver>
      <message-bundle>org.jboss.seam.core.SeamResourceBundle</message-bundle>
   </application>
   <lifecycle>
      <phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener>
   </lifecycle>
</faces-config>

The Javamail.Providers file, shown in Listing 11, is of no consequence in this example. However, if you ever need to add mailing providers to an application, this would be the file to configure to make Seam mail-aware.

Listing 11. Javamail.Providers

# See http://java.sun.com/products/javamail/javadocs/javax/mail/Session.html

protocol=mock; type=transport; class=org.jboss.seam.mock.MockTransport; vendor=JBoss Seam Integration Tests;

The jboss-seam source POM file, shown in Listing 12, looks pretty standard and not that different from what we've already seem. Again, the dependencies section has been tree-collapsed. Because Seam is being compiled from source, there are multiple dependencies, all of whose binaries can be found in the Seam zip (or tar.gz) lib folder, once unpacked.

Listing 12. jboss-seam source POM file

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>root.project</groupId>
   <artifactId>jboss-seam</artifactId>
   <packaging>ejb</packaging>
   <version>2.0</version>
   <name>jboss seam </name>
   <dependencies>
   ...
  </dependencies>
   <build>
  <sourceDirectory>src/main/java</sourceDirectory>
      <plugins>
         <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <configuration>
               <archive>
                  <manifest>
                     <addClasspath>true</addClasspath>
                  </manifest>
               </archive>
            </configuration>
         </plugin>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      </plugins>
   </build>
</project>
1 2 3 4 5 6 7 Page 5
Page 5 of 7