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:
- I downloaded and installed the latest NetBeans Java EE development environment. This comes with Maven support out of the box.
- 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)
- 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>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
<version>2.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.14</version>
</dependency>
</dependencies>
</dependencyManagement>
</pre>
- 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>
- 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>
- 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.
- Add the Facelets dependency to the war pom: <pre lang="xml"><dependency> <groupId>com.sun.facelets</groupId> <artifactId>jsf-facelets</artifactId> </dependency>
</pre>
- 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.