JSF on Jetty and Maven

Using Jetty to develop webapps is great because it can start the app directly from your maven project in a snap, and even updates it as you edit your JSPs… (almost) live. To see for yourself, you can check this video where Matt Raible shows how to use the yet-to-be released AppFuse 2.0 to create a Hello World webapp in a couple of minutes.

However, for a long time I’ve been quite disappointed by the fact that JSF webapps (I’m using MyFaces, but is the same with other implementations, I’m told) do not work as expected, as the JSF tags are not automatically recognized by Jetty.

It’s not that Jetty can’t do JSF… is that the standard seems to be unclear, and Jetty requires JSF to be in the server’s classpath (check this thread at Nabble).

So, it’s easy… I copy the jars to the right directory under my jetty installation and that’s all. Right?

Wrong. We’re talking about maven here, remember? There’s no local installation.

So… how do I tell Jetty to use those JSF jars? The solution is on the archetypes! Lots of JSF + Jetty archetypes for maven exist… I’ve just been too lazy to look at them. Just modify your pom.xml and add the jars (along with any dependencies you need) as dependencies for the jetty plug-in.

For my fellow lazy friends, here’s my set up:

      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <configuration>
          <contextPath>/</contextPath>
          <scanIntervalSeconds>10</scanIntervalSeconds>
        </configuration>
        <!-- Java Server Faces & Web APIs-->
        <dependencies>
          <dependency>
            <groupId>org.apache.myfaces.core</groupId>
            <artifactId>myfaces-api</artifactId>
            <version>1.1.4</version>
          </dependency>
          <dependency>
            <groupId>org.apache.myfaces.core</groupId>
            <artifactId>myfaces-impl</artifactId>
            <version>1.1.4</version>
          </dependency>
          <!-- I use log4j with commons-loging, so I also need this -->
          <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
          </dependency>
        </dependencies>
      </plugin>



%d bloggers like this: