Setting up a transparent Seam Maven project

This entry explains how to set up an transparent Seam Maven project in a very easy way. This is especially of interest when you are not looking for all the scaffolding possibilities and would really like to explore and learn Seam. This is a full Java EE project with maven modules for the ear, war and ejb jar. This project can be downloaded in the link at the end of this entry. Note that this project contains some code and configuration (seam, facelts, hibernate) that you can use to explore Seam, Facelets etc (it is easy to remove to use it for your own project). This post does not explain Seam details (we will post one soon).

The image below is used as a reference throughout this entry; it shows the structure and links between the different maven projects.

maven seam

It all starts with a directory structure as shown in (1). Create four maven projects using mvn archetype:generate (all three are of default type maven-archetype-quickstart): one for the main pom (named seam.maven.demo here) and three for the ear, ejb and war respectivily. Your folder should have four subfolder, one for each project: the main, ear, ejb and war. From here one we will be using the names as shown in the image above.

Next (2) open the main pom file (seam.maven.demo) . This one will act as the main pom for this project. You need to do a couple of things here:

  1. change the packging to pom: <packaging>pom</packaging>
  2. Make it inherit from org.jboss.seam:root:2.1.2.CR1 (or another version). This makes it easy to add dependencies to this project without having to reference the version names. (this is shown a (3) in the diagram above)
  3. Add the other poms as modules referencing relative (so in this case prefixed with ../, for example: <module>../seam.maven.demo.ear</module> (you will have three sibling module elements in a single modules parent element)

Note that the pom file in the attached demo also includes the maven-overview-plugin to depict dependencies using an image (see the google code’s plugin page)

Now let’s concentrate on the other pom files (4). On each of these set the parent to the main pom file:

    com.coursewarefactory
    seam.maven.demo
    1.0-SNAPSHOT
    ../seam.maven.demo/pom.xml

And change the packaging to the appropriate value (ear, ejb and war respectively)

Now go back to the main pom file and reference (relative) the other projects as modules (5):

    ../seam.maven.demo.ear
    ../seam.maven.demo.war
    ../seam.maven.demo.ejb

Now we will set up the other project dependencies (6)

  • The ear project needs dependencies to the ejb and war projects

        ${groupId}
        seam.maven.demo.ejb
        ${version}
        ejb
     
        ${groupId}
        seam.maven.demo.war
        ${version}
        war

  • The war project needs a dependency to the ejb project

The last step is to setup the dependencies per project and configure the ear plugin.

The war project requires some dependencies (this depends also on what you would like to use, Facelets, IceFaces etc). Notice how the version are not supplied, this is because our parent pom inherits from a seam master pom.

    org.jboss.seam
    jboss-seam-ui
 
    org.jboss.seam
    jboss-seam-debug
 
<!-- if using Facelets -->
 
    com.sun.facelets
    jsf-facelets
 
    org.richfaces.ui
    richfaces-ui
 
<!-- The "provided" dependencies are only need for compilation -->
 
    javax.servlet
    servlet-api
    provided
 
    org.jboss.seam
    jboss-seam
    ejb
    provided

The ejb project’s dependencies

    org.jboss.seam
    jboss-seam
    ejb
    provided
 
<!-- in case you are using hibernate-->
 
    org.hibernate
    hibernate
    provided
 
    org.hibernate
    hibernate-entitymanager
    provided
 
    org.hibernate
    hibernate-annotations
    provided
 
    org.hibernate
    hibernate-validator
    provided
 
    javax.ejb
    ejb-api
    provided

The ear’s dependencies:

    org.jboss.seam
    jboss-seam
    ejb
 
    org.jboss.el
    jboss-el
 
<!-- these were added before-->
 
    ${groupId}
    seam.maven.demo.ejb
    ${version}
    ejb
 
    ${groupId}
    seam.maven.demo.war
    ${version}
    war

Finally you need to configure the maven-ear-plugin (7) in the ear project so that the war, ejb Java EE modules are added and in addition the:

  • The org.jboss.seam:jboss-seam as an ejb-module
  • The org.jboss.el:jboss-el as an jar module in the lib directory of the ear file

This is the complete listing for the plugin configuration

        maven-ear-plugin
 
            Maven SEAM Sample
            Maven SEAM Sample
            maven-sample-app
 
                4
 
            5
 
                    ${groupId}
                    seam.maven.demo.war
                    /maven-seam
                    seam-maven-demo-war-${version}.war
 
                    ${groupId}
                    seam.maven.demo.ejb
                    seam-maven-demo-ejb-${version}.jar
 
                    org.jboss.seam
                    jboss-seam
 
                    org.jboss.el
                    jboss-el
                    lib

To now build the entire project, go to the main pom and run the package command:

% cd   seam.maven.demo
% mvn package

The ear file can be found in the ear’s project target directory: (see line 5 below)

% ls ../seam.maven.demo.ear/target/
total 7.4M
-rw-r--r-- 1 johhny users  669 2009-12-31 12:00 application.xml
-rw-r--r-- 1 johnny users  172 2009-12-31 12:00 jboss-app.xml
-rw-r--r-- 1 johhny users 7.4M 2009-12-31 12:00 maven-sample-app.ear
drwxr-xr-x 4 johhny users 4.0K 2009-12-31 12:00 seam.maven.demo.ear-1.0-SNAPSHOT

You can download the complete project here

  • Share/Bookmark

About this entry