Mavenising seam projects [ part 1 ].

Seam [1] is a  very powerful framework for developing java EE web-based applications. It is the only java framework which glues all the tiers of a typical java EE web application together. It is no surprise that many seam features like using EJB 3.0  (for seam any pojo which is a seam component) directly as JSF backing beans, declarative scoping and conversation scope  has been included in the new Contexts and Dependency Injection for Java EE 6 (CDI) also known as JSR 299 [2].  JSR 299 combines best features of seam, Google Guice [3] and Spring [4]. Seam also has tons of other features which make it a very useful framework to learn for any Java developer. Seam by default uses ant. The seam-gen tool creates an ant project and itself is a wrapper to different ant targets.

Maven on the other hand is emerging as the de-facto building tool for java. As I have already mentioned before, maven gives you a very good overview of your project and you are not lost in minor details. Those details are automatically taken care of. With seam projects, maven is especially useful because you know which dependencies are needed.

When I started learning seam, by reading the very popular book Seam in Action by Dan Allan [5], I had already switched to maven for all my projects. I decided to mavenise the examples of the book. There are many such projects. The seam documentation also points to the seam-maven-refimpl project [6] which provides a nice template for any seam project. As I wanted to find out how the maven implementation a seam project differs from that of a standard java EE project first hand, I didn’t use the template provided by this project. I just started with a standard java EE project and started adding seam dependencies to it, until I had a working example.

The implementation  can be found here. Please feel free to point out any mistakes or suggest improvements to th code.

I have also tried to convert the first examples of the book Seam 2.x Web Development by David Salter [7]. These examples are very simple i.e. without persistence, richfaces etc, although they use state less session beans.

Here I will discuss the Open18 example from the Seam In Action book in detail.

Here is the pom file of the main parent project which is no different from an ordinary Java EE project. The only seam specific thing is the jboss repository entry at the end.

<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.hardik.seaminaction</groupId>
  <artifactId>Open18</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Open18</name>
  <url>http://maven.apache.org</url>
  <modules>
  	<module>action</module>
  	<module>model</module>
    <module>war</module>
    <module>ear</module>
  </modules>
  <build>
  	<plugins>
  		<plugin>
  			<groupId>org.apache.maven.plugins</groupId>
  			<artifactId>maven-compiler-plugin</artifactId>
  			<configuration>
  				<source>1.6</source>
  				<target>1.6</target>
  			</configuration>
  		</plugin>
  	</plugins>
  </build>
  <dependencyManagement>
  	<dependencies>
  		<dependency>
  			<groupId>com.hardik.seaminaction</groupId>
  			<artifactId>ear</artifactId>
  			<version>1.0-SNAPSHOT</version>
  		</dependency>
  		<dependency>
  			<groupId>com.hardik.seaminaction</groupId>
  			<artifactId>war</artifactId>
  			<version>1.0-SNAPSHOT</version>
  		</dependency>
  		<dependency>
  			<groupId>com.hardik.seaminaction</groupId>
  			<artifactId>action</artifactId>
  			<version>1.0-SNAPSHOT</version>
  		</dependency>
        <dependency>
  			<groupId>com.hardik.seaminaction</groupId>
  			<artifactId>model</artifactId>
  			<version>1.0-SNAPSHOT</version>
        </dependency>
  	</dependencies>
  </dependencyManagement>
    <dependencies>
        <!-- hibernate dependencies with provided scope -->
    </dependencies>

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

Links:

  1. Seam
  2. Contexts and Dependency Injection in Java EE 6 (JSR 299)
  3. Google Guice
  4. Spring framework
  5. Seam in action
  6. Seam maven reference implementation
  7. Seam 2.x Web Development

About these ads