About software development for the enterprise. Focus on Java EE and more general Java platforms.
You'll read a lot about Conferences, Java User Groups, Java EE, Integration, AS7, WildFly, EAP and other technologies that hit my road.

Monday, January 11, 2010

Running Mojarra 2.0.2 on GlassFish v2.1.1

07:44 Monday, January 11, 2010 Posted by Markus Eisele
, , , ,
First of all: Happy new year to all of my readers. I had a quite busy time during the start of the new year. But now, everything seems back to normal operation and I can start over blogging about my fav topics.

A few days ago, a co-worker asked me, about running JSF 2.0 on GlassFish v2.x. I realy was not shure about this first. The JSF 2.0 spec is part of JEE 6 and should work with JDK 1.6. But what about JEE 5 and JDK 1.5? Reading the spec clearly states that it is based on Java 2 Platform, Standard Edition, version 5.0. Ok. This should work according to the spec.

Let's start.
Grep the latest Mojarra 2.0 Download from the projects websites. If you are there already, also get the sources. We will need them later ;)
Extract the binary distribution (mojarra-2.0.2-FCS-binary.zip/.tar) and setup the example build. I was trying to get the "guessNumber" example (mojarra-2.0.2-FCS\samples\guessNumber) working and will use this further on, too.
If you have everything in place, switch to your favorite JDK 1.5 version (I was using the latest 1.5.0_22) and give it a try (mvn clean install).
Without chaning anything, you will notice, that this will not work:

[INFO] Compilation failure
X:\mojarra-2.0.2-FCS\samples\guessNumber
\src\main\java\guessnumber\ClientSideValidatorHandler.java:[42,-1] cannot access
javax.faces.component.UIComponent
bad class file: ~.m2\repository\javax\faces\jsf
-api\2.0\jsf-api-2.0.jar(javax/faces/component/UIComponent.class)
class file has wrong version 50.0, should be 49.0

What does this version thing mean? It states, that the UIComponent.class was compiled with JDK 1.6 and you are trying to use it with JDK 1.5. Fail :|

Lets correct this.
Next is to extract the sources from the download (mojarra-2.0.2-FCS-source.zip/.tar) and compile a JDK 1.5 compliant jsf-api project. Thank god, the JSF guys know how to setup a build. Copy the build.properties.glassfish.orig to a build.properties file and add your jsf.build.home. Beeing behind a corp firewall forces you to add the needed proxy configurations to your ~/.m2/settings.xml file next. Now call ant and build Mojarra 2.0.2.

Now we are going to use our two new jar files. Find
the jsf-api.jar in \mojarra-2.0.2-FCS-source\jsf-api\build\lib and the
the jsf-impl.jar in mojarra-2.0.2-FCS-source\jsf-ri\lib and install them to your local maven repository. I was using other version numbers but same group and artifact ids for testing.

mvn install:install-file -DgroupId=javax.faces -DartifactId=jsf-api -Dversion=2.0.2 -Dpackaging=jar -Dfile=jsf-api.jar

mvn install:install-file -DgroupId=javax.faces -DartifactId=jsf-impl -Dversion=2.0.2 -Dpackaging=jar -Dfile=jsf-impl.jar

Now you have to change the pom.xml of your guessNumber example to reflect the changes. If you are not using a JEE5 SDK, you also have to add the javax.annotation dependency.

<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.2</version>
</dependency>


<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2</version>
</dependency>

Almost finished now. Next step is to add a sun-web.xml to the webapp (guessNumber\src\main\webapp\WEB-INF). It should contain:

<class-loader delegate="false"/>
<property name="useBundledJsf" value="true" />

Now you are ready to go. Call mvn clean install and deploy your guessNumber\target\guessNumber.war to your GlassFish v2.1.1 domain. And you are done!