Thursday, June 9, 2011

Primefaces on Google App Engine

There are many posts about running jsf 2 and primefaces with google app engine. This is just another one of those. Following versions are used:

1) Google app engine SDK 1.5.0.1
2) Mojarra jsf-api-2.1.1, jsf-impl-2.1.1
3) Primefaces 3.0.M2

Running primefaces showcase on google app engine was pretty straightforward except for couple of tweaks.

Here are the steps:

1) Download google app engine SDK and extract. Well that't it for step 1.

2) Checkout primefaces examples. Here is the command for quick copy-paste
svn checkout http://primefaces.googlecode.com/svn/examples/trunk/ primefaces-examples

3) Run showcase to just to feel good about progress so far.
$ cd primefaces-examples/showcase
$ mvn jetty:run

I had to edit pom.xml to change jstl groupId to javax.servlet.

point the browser to http://localhost:8080/prime-showcase/ui/home.jsf. Warning, you may find it hard to resist playing around with primefaces at this point. Remember, the idea is to run it on google app engine.


4) Now the little tweak. Mojarra uses javax.naming.InitialContext which is a restricted class in google app engine. Mojarra code does seems to check if InitialContext can be loaded but apparently it doesn't work in app engine. Tweak was to disable it completely by modifying com.sun.faces.config.WebConfiguration and return false from canProcessJndiEntries method. It's not hard to build mojarra from source except that the build instructions are hard to find. If you plan to build it from source, you may find these tips handy

a) copy any of build.properties.container file to build.properties
b) build jsf-tools, jsf-api and jsf-impl in this order.

Can also download prebuilt jars for jsf-api here and jsf-impl here.

Install these custom built mojarra using following commands

$ mvn install:install-file -Dfile=jsf-api-2.1.1-custom.jar -DgroupId=com.sun.faces -DartifactId=jsf-api -Dversion=2.1.1-custom -Dpackaging=jar

$ mvn install:install-file -Dfile=jsf-impl-2.1.1-custom.jar -DgroupId=com.sun.faces -DartifactId=jsf-impl -Dversion=2.1.1-custom -Dpackaging=jar

5) Final step. Putting it all together. Change directory to showcase and cleanup the project (otherwise existing mojarra jars interfere).

$ mvn clean

Edit pom.xml, look for gae profile and modify jstl dependencies to set version as 2.1.1-custom.
Build the war using gae profile

$ mvn package -P gae

This should create a war and expanded war directory in target. Google appengine sdk can not run war locally but can work with expanded war directory.

$ GOOGLE_SDK/bin/dev_appserver.sh target/prime-showcase-1.0.0-SNAPSHOT

Voila.

Monday, September 8, 2008

learning

We are not capable of doing complicated things.
Learning is a process by which complicated things are made simple, so that we can do it.