Archive for the ‘Development’ category

GAE + PrimeFaces + Spring + Maven

January 19, 2010

Ok, the goal I was looking for here was to be able to have a personal (so not for work) development environment where I could write and host small applications in Java with a nice WEB 2.0 type interface. The final technology set I rested on (for many reasons not discussed here) was:

  • Google App Engine (GAE) – for hosting
  • Spring – for ease in server development
  • JSF 2.0 – PrimeFaces – for nice GUI
  • Maven – for build management

Looking around I couldn’t find any project that seemed to integrate these elements so I started with the following base projects and adjusted and hacked my way until I got something I was relatively happy with:

The end result of my integration effort can be found here:

http://gae-primefaces-spring-maven.appspot.com/

and the source here:

http://gae-primefaces-spring-maven.googlecode.com/svn/gae-primefaces-spring-maven

Things I don’t quite like at the moment and would still like to improve on are:

  • Having to re-run with gae:run every time I make a small change. It would be much better if it was possible to do everything in Eclipse while still having a maven project. There are several people working on this so I will wait to see what initiatives come out of that.
  • Not quite happy about having to use PrimeFaces 1. Not being a PrimeFaces expert I’m not sure what I am missing out on between the different versions but would of course liked to have integrated with the latest and greatest.

If you can assist on any of these please drop me a comment and I will endeavour to update the project.

For instructions on how to get it running and some of the errors I encountered along the way read on

Getting the sample running

Pre-conditions

You need Maven2 installed and some way to grab the code from the SVN repository.

To run locally

  1. Download project from Svn (basically a hard-earned POM) – SVN Location: http://gae-primefaces-spring-maven.googlecode.com/svn/gae-primefaces-spring-maven
  2. Kick off a “mvn gae:run” – This will run the application locally.
  3. Once this has completed use a browser and go to http://localhost:8080/

To run on GAE

  1. Setup an application on GAE
  2. Update the Pom.xml property <gae.application.appId> to be the same as the appId you setup on GAE.
  3. Kick off a “mvn gae:deploy” – Enter your login and password details when prompted.
  4. When finished go to http://<gae.application.appId>.appspot.com/ to view your PrimeFaces app online through GAE.

Some resources used

Problems Encountered

————————————————————————————

Error:  
19/01/2010 3:39:43 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
SEVERE: Error Loading Library: jar:file:/C:/Documents and Settings/bhaire/workspace/GAE-PrimeFace-Maven/target/gae-prime
faces-maven-example-1.0-SNAPSHOT/WEB-INF/lib/primefaces-2.0.0.RC.jar!/META-INF/primefaces-p.taglib.xml
java.io.IOException: Error parsing [jar:file:/C:/Documents and Settings/bhaire/workspace/GAE-PrimeFace-Maven/target/gae-
primefaces-maven-example-1.0-SNAPSHOT/WEB-INF/lib/primefaces-2.0.0.RC.jar!/META-INF/primefaces-p.taglib.xml]:
at com.sun.facelets.compiler.TagLibraryConfig.create(TagLibraryConfig.java:410)
Solution:
Use primefaces1.0 instead of 2.0
————————————————————————————

Error:
org.springframework.web.context.ContextLoader initWebApplicationContext: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.context.annotation.internalPersistenceAnnotationProcessor’: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/naming/NamingException
Solution: Don’t use the all in one spring package. Split it up.

————————————————————————————

Error:
Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@9af0b1{/,/base/data/home/apps/brendanjsf2template/4.339128544091663199} java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThread)
Solution: Add the following to web.xml:
<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>
————————————————————————————

Error:
java.lang.NullPointerException: No API environment is registered for this thread.
Solution:
must run “mvn gae:run”. I was running “mvn jetty:run” or “mvn tomcat:run”. I believe the reason this does not work is because it must setup the Data nucleus API environment and gae:run does this while of course the others don’t.

————————————————————————————
 
Error:
java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google  App Engine developer’s guide for more details.
Solution:
Include custom com.sun.faces.config.WebConfiguration class
————————————————————————————
Error:
com.sun.faces.config.ConfigurationException: It appears the JSP version of the container is older than 2.1 and unable to
locate the EL RI expression factory, com.sun.el.ExpressionFactoryImpl.  If not using JSP or the EL RI, make sure the co
ntext initialization parameter, com.sun.faces.expressionFactory, is properly set.
Solution:
Include el-api and el-impl from https://uel.dev.java.net/ (version 1.0. used)
————————————————————————————
Error:
Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@ad5fab{/,/base/data/home/apps/brendanjsf2template/0.339175661962918277} com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary is a restricted class. Please see the Google App
Solution:
Add the following jars:
* serializer.jar
* xalan.jar
* xercesImpl.jar
* xml-apis.jar
* xsltc.jar
————————————————————————————