GAE + PrimeFaces + Spring + Maven

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
————————————————————————————
Explore posts in the same categories: Development

Tags: , , , , , ,

You can comment below, or link to this permanent URL from your own site.

18 Comments on “GAE + PrimeFaces + Spring + Maven”


  1. Nice work! In current PrimeFaces-2.0.0-SNAPSHOT, facelets-taglib.xml should be fixed. In 2.0. RC there was a problem with that. You can try with a nightly build.

  2. Hendy Irawan Says:

    Wow excellent work, Brendan!

    I’ve been meaning to try this, but you beat me to it big time!

    I don’t really have a problem with PrimeFaces. Actually I probably will prefer PrimeFaces due to its mobile / TouchFaces support.

    Over time, RichFaces/IceFaces/Trinidad will come out of alpha and hopefully they’ll work with GAE too.

    I’m grateful that you have good news with PrimeFaces and GAE, Brendan. 🙂

    Regarding Maven, I agree with you. Without proper integrated development cycle, Maven development sucks big time.

    I prefer using Maven Ant Tasks for dependency management for GAE, my build.xml is like this:

    
    
    
        
         retrieve dependencies with ivy">
    		
    			
    	        
    			
    			
    			
    		
    		
    			
    			
    		
        
    
    

    I still get some of Maven’s convenience while none of its inconveniences (using the same old Google App Engine for Eclipse development model).

  3. Hendy Irawan Says:

    Haha, I knew my code will get screwed up.

    For those interested, here it is: http://pastebin.com/f53b245b1

    • brendanhaire Says:

      Hi Hendy,

      Thanks for the feedback. Regarding the 500 error I have seen it before but then it disappeared without me changing anything. I believe it is timing out when retrieving the data from data nucleus but I am unsure why this is happening and then only sometimes (see Exception below). It probably has something the way I am interacting with the data nucleus datastore. I cleared out the list of books people had entered and it seems to be working again.

      Exception Sniplet:
      com.sun.facelets.FaceletViewHandler handleRenderException: Error Rendering View[/bookList.xhtml]
      com.google.apphosting.api.DeadlineExceededException: This request (12fbfc9a3e26c3d8) started at 2010/02/10 23:59:53.390 UTC and was still executing at 2010/02/11 00:00:22.162 UTC.
      at java.util.LinkedList.getFirst(Unknown Source)
      at org.datanucleus.store.appengine.DatastoreFieldManage


  4. For JSF 2 and PrimeFaces2, make sure you dont have FaceletViewHandler defined in faces-config.xml as it is standard now.

    • Nikolaj Hansen Says:

      cagataycivici,

      Without the definition of a FaceletViewHandler the Primefaces components are not rendered at all. So it seems they do not hook in with the standard one automatically.

  5. Gurudutt Says:

    I have been trying to add Ajax support to this.But I get this ” Tag Library supports namespace: http://java.sun.com/jsf/core, but no tag was defined for name: ajax”.I am pretty new to JSF.Does JSF 2.0 not supprt Ajax?

  6. ken Says:

    I’m using myfaces. When I run my app in Eclipse, there’s no problem. When I run it on appengine, I get:

    Caused by: java.lang.RuntimeException: java.io.InvalidObjectException: enum constant attributes does not exist in class javax.faces.component.UIComponent$PropertyKeys
    at com.google.apphosting.runtime.jetty.SessionManager.deserialize(SessionManager.java:413)

    Any ideas?

  7. Gilberto Oliveira Says:

    Thank you! Nice job.

  8. Aditya Says:

    Nice sample.
    Do you have some tips / experience to share regarding GAE persistence layer?

  9. elfdanielDaniel Says:

    Nice one.
    It s the first example I saw running on host.
    I ve played with JSF only with localhost ’till now.
    Probably it s the only way to have JSF free host right now.

    Thx a lot. Gonna try it.

  10. Daniel Says:

    Hai Brendan,

    I tried this tutorial to get JSF running in google app engine

    http://java.wildstartech.com/Java-Platform-Enterprise-Edition/JavaServer-Faces/javaserver-faces-20/configuring-javaserver-faces-20-to-run-on-the-google-appengine

    But it doesn’t work.

    Is there any tutorial you know just to setup the first hello world with google app, maven and jsf?

    thx a bunch before

    regards


  11. Tuaoridu uayevuma; Doctor Approved Prosolution Pills iyegazeu epuifveu enenayui rieauti yeoheyajo edegxanubi!

  12. gelosoft Says:

    I just want to ask, what database you’re using here..?


Leave a comment