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!
Post a Comment
3Comments
Ok. Forgett about building the sources. Seems as if I had a version from a bogus repository in place trying it. Retrying it today did not show up the error again. Anyway, now you know, how to build the distribution from sources and bundle your own version :)
ReplyDeleteHello, nice post. Iam trying to reproduce it, but I still could not make it work )-: Any idea? Thanks.
ReplyDelete1. Download and install fresh glassfish 2.1.1
2. Download jsf-api, jsf-impl v2.0.4 and copy them to $glassfish/lib.
3. Iam using java 1.6 so I do not need to recompile it.
4. Load "guessNumber" example in NetBeans 6.9.1
5. Deploy - failed.
Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Error while running ejbc -- Fatal Error from EJB Compiler -- File name dir or drive is not correct at java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:396)
at java.io.File.getCanonicalPath(File.java:559)
Hi Jan,
ReplyDeletethis does not sound like a JSF setup problem. More like a problem in (one of) your app(s). Make sure, you start with an empty domain and don't deploy anything beside the guessNumber example.
M