Building Seam with Maven 2

March 26, 2008 at 7:03 pm | Posted in Build, Java, Software Development | 5 Comments
Tags: , , , , , ,

JBoss Seam gives you a great build support if you want to go with Ant. But what about Maven 2? There doesn’t seem to be a lot of documentation about it. Here’s how I got it running. First of all you need to create a multi-module project. Maven 2 requires to have a POM for every artifact you want to build. What you need to set up is one project (through a directory) per artifact. The book “Better Builds with Maven” describes this procedure very well. After setting it up you should have something similar to this:

project
 - pom.xml
 |- ear
 |  - pom.xml
 |- ejb
 |  - pom.xml
 |- war
 |  - pom.xml

WAR will hold your JSF application files, EJB contains all EJB-related definitions and EAR ist just another project for building the enterprise archive. Each project will have their own POM file. On top of that you will have a parent POM which allows you to build all modules. In your parent POM define the Seam parent POM for usage:

<parent>
   <groupId>org.jboss.seam</groupId>
   <artifactId>parent</artifactId>
   <version>2.0.1.GA</version>
</parent>

You find the parent POM in the JBoss repository:

<repositories>
   <repository>
      <id>jboss-repository</id>
      <name>JBoss Repository</name>
      <url>http://repository.jboss.org/maven2</url>
   </repository>
</repositories>

Furthermore, you need to define your sub-modules (ear, ejb, war) as dependencies and modules. Add the JBoss Seam libraries you need. Moreover, don’t forget to set JDK >= 1.5 to build your code. Once you set up your project’s parent POM you’re ready to work on the module POMs. The only thing you have to do for the module POMs is to use your project’s parent POM and define the dependencies you need. For the EAR artifact you can use the Maven EAR Plugin to generate application.xml and jboss-app.xml. For a full code example have a look at the DVDStore Seam example build with Maven 2.

Advertisements

5 Comments »

RSS feed for comments on this post. TrackBack URI

  1. thanks for the leads, but for a maven beginner like me it’s a bit too fast :-).
    You give a link to “DVDStore build with maven” but this example doesn’t include the seam parent artefact in main pom.xml and if the ear, ejb and war modules are well define as module they are not define as dependencies in this same pom.xml.
    I guess this example is a bit outdated (2006) so how would you correct it to make it fit today requirement ?

  2. Antoine,
     
    I had a look at the example again. You’re right. The example parent POM does not use the JBoss Seam root POM. They define a list of Seam JARs in the dependencies list instead. Using the Seam root POM helps you to avoid that.
     
    To define the sub-modules add them as modules:


    <modules>
       <module>web</module>
       <module>ejb</module>
       <module>ear</module>
    </modules>

     
    If you want to make sure that you use a specific version for your sub-modules you can enforce that in the dependenyManagement section (this is optional):


    <dependencyManagement>
       <dependencies>
          <dependency>
             <groupId>de.example.dvdstore</groupId>
             <artifactId>dvdstore-web</artifactId>
             <version>${project.version}</version>
          </dependency>
          <dependency>
             <groupId>de.example.dvdstore</groupId>
             <artifactId>dvdstore-ejb</artifactId>
             <version>${project.version}</version>
          </dependency>
          <dependency>
             <groupId>de.example.dvdstore</groupId>
             <artifactId>dvdstore-ear</artifactId>
             <version>${project.version}</version>
          </dependency>
       </dependencies>
    </dependencyManagement>

     
    An up-to-date resource to have a look at is the source code of “Seam in Action”. There’s one example project that uses Maven 2 to build it:
     
    http://seaminaction.googlecode.com/svn/trunk/prototype/projects/golf-tournament-service/
     
    Hope this helps.
     
    Ben

  3. There is a new article by SEAM:
    http://www.seamframework.org/Community/InfoCreatingSeamProjectInMaven2

  4. checkout http://github.com/mbogner/mbook/tree/master for a simple/empty j2ee seam project.

    took me quite a time to get it running.

    hope its helpful.

    manuel

  5. Very nice post. I just stumbled upon your weblog and wanted to
    say that I have truly enjoyed browsing your blog posts. In any case I will be subscribing to your rss feed and I hope you write again very
    soon!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: