So a recent update to the Google App Engine SDK broke my JSF 2.0 web application. I received this message on local server start-up:
WARNING: Error starting handlers
Throwable occurred: java.lang.NoClassDefFoundError:
javax.naming.InitialContext is a restricted class. Please see the Google
App Engine developer’s guide for more details.
Apparently this was due to how JSF checks if it can use InitialContext first (bug report)- by invoking it. Unfortunately, this sends GAE into a panic, since javax.naming.InitialContext is not one of the whitelisted JRE classes.
**Edit 3: for your convenience, I have pre-packaged this solution into its own .jar file. See bottom of post for further details.
Note: If you haven’t yet set up your JSF-enabled GAE project, follow this guide.
The solution: override the JSF implementation of WebConfiguration, at least until GAE or Mojarra put out a fix. At the very least, this will let you once again use JSF on 1.2.6 locally – I’m still hitting an error 500 when deployed on the app server, but it might be due to some other libs in my web app*. Please post a comment if you find a better solution!**
Here are the steps I took:
- Add jsf-api.jar and jsf-impl.jar to your build path.
- Create the package structure com.sun.faces.config
- Create a WebConfiguration class in com.sun.faces.config and put in the following code [.java link].
Make sure that, if you’ve just updated the GAE plugin in Eclipse, that your project has been updated to use GAE 1.2.6 too.
*Edit: the error 500 I stated earlier was in fact due to another library causing a crash – probably another 1.2.6 incompatibility? So if you implement this patch, other libraries aside, you should be able to run your app locally and on app engine.
Edit 2: the error 500 was due to an old Jersey core/client implementation, and upgrading to 1.0.3 fixed it. Also, if you’re in Eclipse and need to upgrade your 1.2.5 web project to 1.2.6 but get an error about “dev_appserver” or “KickStart”, just add the following argument to your Run Configuration’s Arguments/vm tab:
Where C:\eclipse is where Eclipse has been installed.
**Edit 3: for your convenience, I have pre-packaged this solution into its own .jar file, which can be used interchangeably with the official jsf-impl.jar. Neither jsf-impl-gae.jar or jsf-api.jar, or the aforementioned solution have to be on the build path with this solution. Just place this in /war/WEB-INF/lib and delete the original jsf-impl.jar.
And if you’re interested in the fix on the Sun Jersey Core library, see my post here.