Maven Simplifies Seam and Facelets Development, if You Can Handle the XML

As part of my digitization and cleanup effort, I’m going through a lot of documents. One document I discovered is an old printout of a Coffeecrew tutorial. The document on Facelets, Seam, NetBeans and Glassfish was their first and last foray into English howto’s. Which is too bad, because it is high quality and has very good writing.

While reading and trying out the tutorial, I couldn’t help but think that using Maven could really simplify some of the steps. So I tried it out:

  1. I downloaded and installed the latest NetBeans Java EE development environment. This comes with Maven support out of the box.
  2. Within the IDE, I created a new project. More specifically a Maven enterprise application. If the plugin executes correctly, you will now have 4 projects (ear, ejb, pom and war)
  3. I like to use dependency management in Maven, so I added the following to the pom.xml inside the pom project: <pre lang="xml"><repositories> <repository> <id>jboss-snapshot</id> <name>The JBoss maven repo</name> <url>http://snapshots.jboss.org/maven2</url> </repository> <repository> <id>java.net-m1-releases</id> <name>Java.net Maven1 Repository - for javax.faces, javax.el, com.sun.el, and com.sun.facelets releases</name> <url>http://download.java.net/maven/1/</url> <layout>legacy</layout> </repository> </repositories>
&lt;dependencyManagement>
    &lt;dependencies>
        &lt;dependency>
            &lt;groupId>org.jboss.seam&lt;/groupId>
            &lt;artifactId>jboss-seam&lt;/artifactId>
            &lt;version>2.2.1-SNAPSHOT&lt;/version>
        &lt;/dependency>
        &lt;dependency>
            &lt;groupId>com.sun.facelets&lt;/groupId>
            &lt;artifactId>jsf-facelets&lt;/artifactId>
            &lt;version>1.1.14&lt;/version>
        &lt;/dependency>
    &lt;/dependencies>
&lt;/dependencyManagement>

</pre>

  1. Next, it’s easy to configure the EAR project and its application.xml from within Maven. There’s no need to write it manually. Add this to the maven-ear-plugin configuration inside the pom.xml of the ear: <pre lang="xml"><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <version>2.3.2</version> <configuration> <version>5</version> <modules> <webModule> <groupId>com.streamhead</groupId> <artifactId>seamhelloworld-web</artifactId> <contextRoot>/seamhelloworld</contextRoot> </webModule> <jarModule> <groupId>org.jboss.seam</groupId> <artifactId>jboss-seam</artifactId> <includeInApplicationXml>true</includeInApplicationXml> </jarModule> </modules> </configuration> </plugin>

</pre>

  1. And also add the Seam dependency in both the pom file of the ear and ejb project: <pre lang="xml"><dependency> <groupId>org.jboss.seam</groupId> <artifactId>jboss-seam</artifactId> </dependency>

</pre>

  1. You will still need to create the ejb-jar.xml inside the ejb project as described in the howto. I don’t think there’s a Maven plugin for that. I’m not sure if that would be very helpful anyway.
  2. Add the Facelets dependency to the war pom: <pre lang="xml"><dependency> <groupId>com.sun.facelets</groupId> <artifactId>jsf-facelets</artifactId> </dependency>

</pre>

  1. And that’s it as far as setup goes. Everything else is 100% development of your application.

The main advantage is that you don’t have to go around hunting for releases. You don’t have to extract them and add them to libraries in your IDE. You can just go ahead and start developing.

I think Maven is a great solution for dependency and configuration issues. It does take some getting used to the XML syntax, but once you get through that initial hurdle, Maven is a tool that belongs in any Jave developer’s tool belt.

Note: Seam doesn’t work on GlassFish v3, so you will have to stick to v2.1 for the time being.