Joshua Java

Seam and Maven

Posted on: December 15, 2007

I know that Seam is by default use ant for building the project and the seam-gen generates the ant projec structure, but there are several reasons I found quite worthy to use maven with Seam.

  1. Seam requires alot of library and they are often comes in large size such as the embeddable-jboss library. So what is important about it? It is important if you are doing a project where the developers spans across several countries. You still don’t get it? It will be a problem if you are going to check out from the source repository with all those libraries.
    For people that comes from a country where bandwith is cheap, this might not be a problem but for people like me where bandwith here is expensive this is a problem.
  2. Also it will be a problem if new libraries comes/has been released and you must update it to the source repository back and forth. Again, it’s only a problem for people that comes from a country where bandwith is expensive.
    With maven you only required to change a small property inside pom.xml and then just commit back those pom.xml to the source repository instead of deleting the library from the source repo, then commit it back again. Get the idea?

So now you want to use maven with Seam and you might asked me, what’s the big deal of it? The big deal is the dependency problem you will encounter if you use maven (and perhaps one of the reason why the Seam team don’t use maven with Seam).
Here’s what I mean:
The Seam library depends on JSF 1.2 library, but on the other hand if you use Richfaces, it will depend on JSF 1.1 library. You will likely encounter a ClassCast exception. And if you use a JEE5 appserver, you are most likely do not want maven to download and include the JSF library because most likely the appserver (like Glassfish or JBoss) already included the JSF library.
etc.

So here’s some tips if you want to use maven with Seam regarding the library dependencies:

  1. Exclude the JSF library, with reasons as I have mentioned before.
  2. Exclude the Javassist library if you are going to use JBoss because JBoss already distribute Javassist inside the appserver, otherwise you will get an error from Hibernate saying that it couldn’t create a proxy.
  3. Don’t include JBoss cache if you don’t need it.
  4. Exclude the hibernate library if you are going to use JBoss AS because JBoss already distribute Hibernate inside the appserver.
  5. Make the scope for javax(s) library as provided.
  6. For some library that is continuously updated (such as Seam, Richfaces, and Hibernate), make a property file regarding the version, so you will only change this property once a new library is updated to the maven repo.

Here’s the pom.xml to give you the idea of it.

<project 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.taxandtech.hireway</groupId>
	<artifactId>hireway</artifactId>
<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>hireway</name>
	<url>http://hireway.sourceforge.net</url>

	<dependencies>
		<dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>5.1</version>
            <classifier>jdk15</classifier>
            <scope>test</scope>
        </dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.14</version>
			<scope>provided</scope>
		</dependency>

		<!-- Seam dependencies -->
		<dependency>
			<groupId>org.jboss.seam</groupId>
			<artifactId>jboss-seam</artifactId>
			<version>${seam.version}</version>
			<exclusions>
				<exclusion>
				    <groupId>javax.faces</groupId>
      				<artifactId>jsf-api</artifactId>
				</exclusion>
				<exclusion>
				    <groupId>javax.el</groupId>
      				<artifactId>el-api</artifactId>
				</exclusion>
				<exclusion>
				    <groupId>dom4j</groupId>
      				<artifactId>dom4j</artifactId>
				</exclusion>
				<exclusion>
					<groupId>jboss</groupId>
					<artifactId>javassist</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.jboss.seam</groupId>
			<artifactId>jboss-seam-ui</artifactId>
			<version>${seam.version}</version>
			<exclusions>
				<exclusion>
				    <groupId>javax.faces</groupId>
      				<artifactId>jsf-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.jboss.seam</groupId>
			<artifactId>jboss-seam-debug</artifactId>
			<version>${seam.version}</version>
			<exclusions>
				<exclusion>
				    <groupId>javax.faces</groupId>
      				<artifactId>jsf-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency> 

		<!-- Richfaces dependencies -->
		<dependency>
			<groupId>org.richfaces.framework</groupId>
			<artifactId>richfaces-api</artifactId>
			<version>${richfaces.version}</version>
		</dependency>
		<dependency>
			<groupId>org.richfaces.framework</groupId>
			<artifactId>richfaces-impl</artifactId>
			<version>${richfaces.version}</version>
			<exclusions>
				<exclusion>
					<groupId>javax.faces</groupId>
					<artifactId>jsf-api</artifactId>
				</exclusion>
				<exclusion>
					<groupId>javax.faces</groupId>
					<artifactId>jsf-impl</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.richfaces.ui</groupId>
			<artifactId>richfaces-ui</artifactId>
			<version>${richfaces.version}</version>
			<exclusions>
				<exclusion>
					<groupId>javax.faces</groupId>
					<artifactId>jsf-api</artifactId>
				</exclusion>
				<exclusion>
					<groupId>javax.faces</groupId>
					<artifactId>jsf-impl</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- Hibernate dependencies -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate</artifactId>
			<version>${hibernate.version}</version>
			<scope>provided</scope>
			<exclusions>
				<exclusion>
					<groupId>javax.transaction</groupId>
					<artifactId>jta</artifactId>
				</exclusion>
				<exclusion>
					<groupId>dom4j</groupId>
					<artifactId>dom4j</artifactId>
				</exclusion>
				<exclusion>
					<groupId>jboss</groupId>
					<artifactId>javassist</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-entitymanager</artifactId>
			<version>3.3.1.ga</version>
			<scope>provided</scope>
			<exclusions>
				<exclusion>
					<groupId>jboss</groupId>
					<artifactId>javassist</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.hibernate</groupId>
					<artifactId>hibernate</artifactId>
				</exclusion>
				<exclusion>
					<groupId>jboss</groupId>
					<artifactId>jboss-common-core</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-annotations</artifactId>
			<version>${hibernate-ejb3.version}</version>
			<scope>provided</scope>
			<exclusions>
				<exclusion>
					<groupId>org.hibernate</groupId>
					<artifactId>hibernate</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.drools</groupId>
			<artifactId>drools-core</artifactId>
			<version>${drools.version}</version>
		</dependency>
		<dependency>
			<groupId>org.drools</groupId>
			<artifactId>drools-compiler</artifactId>
			<version>${drools.version}</version>
			<exclusions>
				<exclusion>
					<groupId>xerces</groupId>
            		<artifactId>xercesImpl</artifactId>
				</exclusion>
				<exclusion>
				    <groupId>xml-apis</groupId>
      				<artifactId>xml-apis</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.jbpm</groupId>
			<artifactId>jbpm-jpdl</artifactId>
			<version>3.2.2</version>
		</dependency>

		<dependency>
			<groupId>org.tuckey</groupId>
			<artifactId>urlrewrite</artifactId>
			<version>2.5.2</version>
		</dependency>
		<dependency>
			<groupId>com.octo.captcha</groupId>
			<artifactId>jcaptcha-all</artifactId>
			<version>1.0-RC6</version>
			<exclusions>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring</artifactId>
				</exclusion>
				<exclusion>
					<groupId>xerces</groupId>
            		<artifactId>xercesImpl</artifactId>
				</exclusion>
				<exclusion>
					<groupId>xerces</groupId>
            		<artifactId>xmlParserAPIs</artifactId>
				</exclusion>
				<exclusion>
					<groupId>quartz</groupId>
            		<artifactId>quartz</artifactId>
				</exclusion>
				<exclusion>
				    <groupId>hsqldb</groupId>
            		<artifactId>hsqldb</artifactId>
            	</exclusion>
            	<exclusion>
            	    <groupId>concurrent</groupId>
            		<artifactId>concurrent</artifactId>
            	</exclusion>
            	<exclusion>
            	    <groupId>net.sf.ehcache</groupId>
            		<artifactId>ehcache</artifactId>
            	</exclusion>
            	<exclusion>
            	    <groupId>commons-logging</groupId>
            		<artifactId>commons-logging</artifactId>
            	</exclusion>
            	<exclusion>
            	    <groupId>commons-dbcp</groupId>
            		<artifactId>commons-dbcp</artifactId>
            	</exclusion>
			</exclusions>
		</dependency> 

		<dependency>
			<groupId>javax.activation</groupId>
			<artifactId>activation</artifactId>
			<version>1.1</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.el</groupId>
			<artifactId>el-api</artifactId>
			<version>1.0</version>
			<scope>provided</scope>
  		</dependency>
		<dependency>
			<groupId>javax.faces</groupId>
			<artifactId>jsf-api</artifactId>
			<version>1.2_04-p02</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>

	<build>
		<finalName>hireway</finalName>
<plugins>
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <optimize>true</optimize>
                </configuration>
            </plugin>
<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<skip>true</skip>
				</configuration>
      		</plugin>
<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-site-plugin</artifactId>
				<configuration>
					<locales>en</locales>
				</configuration>
      		</plugin>
		</plugins>
	</build>

	<repositories>
		<repository>
			<id>JBoss Maven Repo</id>
			<name>JBoss Maven Repo</name>
			<url>http://repository.jboss.com/maven2/</url>
		</repository>
		<repository>
			<id>maven2-repository.dev.java.net</id>
			<name>Java.net Repository for Maven</name>
			<url>http://download.java.net/maven/2/</url>
			<layout>default</layout>
		</repository>
	</repositories>
<properties>
		<seam.version>2.0.0.GA</seam.version>
		<richfaces.version>3.1.2.GA</richfaces.version>
		<hibernate.version>3.2.5.ga</hibernate.version>
		<hibernate-ejb3.version>3.3.0.ga</hibernate-ejb3.version>
		<drools.version>4.0.3</drools.version>
	</properties>
	<licenses>
	<license>
			<name>GNU GENERAL PUBLIC LICENSE Version 3</name>
			<url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
		</license>
	</licenses>

	<mailingLists>
		<mailingList>
			<name>Hireway Mailing List</name>
			<subscribe>unsubscribe@googlegroups.com</subscribe>
<post>http://groups.google.com/hireway</post>
		</mailingList>
	</mailingLists>

</project>

Now with maven, not only your project size is small and compact (it quite useful if you use googlecode since googlecode only provides 100MB data store size), but it is easier when you do lot’s of updates regarding the libraries.

Tags: ,

2 Responses to "Seam and Maven"

With seam 2.0.2.SP1 the javassist exclusion should be

javassist
javassist
</exclusion

you may also want to check out vtd-xml, the latest and most advanced xml processing model

vtd-xml

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

%d bloggers like this: