Getting started with Google App Engine and JSF
Posted: March 25th, 2010 | Author: lukas | Filed under: Java | Tags: Google App Engine, Java, JSF | 6 Comments »Some time ago I decided to familiarize with Google App Engine capabilities. Lately I read a document about GAE Java SDK version capabilities. I was surprised that a big part of JEE stack is supported e.g.: JPA and JSF. That moment I decided to make simple JSF-based demo application.
Google App Engine
Google App Engine (GAE) is a hosting service which allows you to run your web application in Google data center infrastructure. GAE is responsible for scalling and assuring accesibility of your application. At this moment Python and Java runtime environments are supported. Using GAE is free up to certain limits. Free version is limited to 1,300,000 requests, 1Gb of outgoing and 1Gb of ingoing bandwidth daily. It is not much but should be sufficient at the begining. You can read about GAE quotas and billing here.
Prerequisites
I’ve used SpringSource Tool Suite 2.3.0 but you can use any Eclipse from version 3.3 to 3.5. You will also need to get and install Google Plugin for Eclipse. I’ve used Software Update feature to install plugin but you can download and install it by hand. For details read official Google App Engine documentation.
Create Google Web Application project
Basically I’ve followed instructions on Configuring JavaServer Faces 2.0 to run on the Google App Engine Using Eclipse page. First I’ve created new Google Web Project by selecting File->New project->Other->Google->Web Application Project.
Then I’ve downloaded following libraries into war/WEB-INF/lib folder:
- Unified Expression Language libraries: el-api-1.1.jar and el-impl-1.1.jar
- JavaServer Faces libraries: jsf-api.jar and jsf-impl.jar
- Apache Xalan libraries: serializer.jar, xalan.jar, xercesImpl.jar, xml-apis.jar, xsltc.jar
TIP: I’ve downloaded xalan-j_2_7_0-bin-2jars.zip version and extracted needed Xalan libraries.
Next thing to do was to copy JavaServer Faces Tag library definition. I’ve downloaded Mojarra source distribution and copied jsf_core.tld and ui.tld files from jsf-ri/conf/share directory into war/WEB-INF directory.
That I’ve updated appengine-web.xml file and added <sessions-enabled>true</sessions-enabled> tag
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>simpleloancalculator</application>
<version>1</version>
<sessions-enabled>true</sessions-enabled>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file"
value="WEB-INF/logging.properties"/>
</system-properties>
</application>
</appengine-web-app>and JSF faces-config.xml and web.xml files with default content
faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
</faces-config>web.xml
<?xml version="1.0" encoding="utf-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Wildstar Technologies, LLC. Google AppEngine JSF 2.0
Template</display-name>
<description>
Template JSF 2.0 application configured to run on the Google
AppEngine for Java.
</description>
<!--
***** GAE 1.3.0 appears to handle server-side state saving. *****
-->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- GAE Bug 1506 JSP 2.1 API but 2.0 Implementation -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<description>
Set this flag to true if you want the JavaServer Faces
Reference Implementation to validate the XML in your
faces-config.xml resources against the DTD. Default
value is false.
</description>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<!--
***** Accommodate Single-Threaded Requirement of Google AppEngine
-->
<context-param>
<description>
When enabled, the runtime initialization and default ResourceHandler
implementation will use threads to perform their functions. Set this
value to false if threads aren't desired (as in the case of running
within the Google Application Engine).
Note that when this option is disabled, the ResourceHandler will not
pick up new versions of resources when ProjectStage is development.
</description>
<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</param-value>
</context-param>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>Then I’ve created index.jsp file which basically redirects all request to welcome.jsf page.
welcome.xhtml file prints welcome message using <h:outputText /> JSF tag.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head id="head">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Welcome to JSF 2.0 on the Google AppEngine!</title>
</h:head>
<h:body id="body">
<f:view contentType="text/html">
<p><h:outputText value="You are now up and running with JavaServer Faces 2.0 on the Google App Engine."/></p>
</f:view>
</h:body>
</html>When I’ve tried to run my project I’ve got following exception:
java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51) at com.sun.faces.config.WebConfiguration.processJndiEntries(WebConfiguration.java:578) at com.sun.faces.config.WebConfiguration.<init>(WebConfiguration.java:114) at com.sun.faces.config.WebConfiguration.getInstance(WebConfiguration.java:174) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:161) at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:530) at org.mortbay.jetty.servlet.Context.startContext(Context.java:135) at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1218) at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:500) at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40) at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:117) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40) at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:117) at org.mortbay.jetty.Server.doStart(Server.java:217) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40) at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:188) at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:147) at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:219) at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:162) at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48) at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113) at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
I’ve double checked all settings and library dependencies but couldn’t figure out the source of this exception. Then I’ve Googled this article. I’ve followed instructions on this blog (thanks Josh) com.sun.faces.config.WebConfiguration class in under my project. Content of this class can be found here.
After that I was able to run my project.
Demo of my application.
Source code with all required libraries.





Hi,
Great article. I am trying to use the source code as starting point. The app works… except that the jsf tags are not rendered, only the html. any ideas? I have tried running local or deployed to google.
Thanks,
rickerg@tds.net
@rickerg I’ve checked-in new version of WebConfiguration.java file (see source in SVN: http://code.google.com/p/whileitcompiles/source/browse/trunk/SimpleLoanCalculator/src/com/sun/faces/config/WebConfiguration.java). I’ve removed obsolete imports which caused compilation errors.
Please give a try with modified version of this file and let me know if it helped with your issue.
That worked. It also helps if I follow the directions! I had failed to un-check the Google Web Toolkit…ugh.
Thanks for the help.
@rickerg I’m glad that it helped.
Hi,
I tried to deploy your source code in MyEclipse 8.6.
I got this error message in the console
“Your project must be configured to use a JDK in order to use JSPs index.jsp /SimpleLoanCalculator/war Unknown Google App Engine Problem”
I believe I didnt miss any steps you mentioned.
Check your project and workspace configuration. Maybe you have JRE configured instead of SKD?