Friday, May 22, 2009

Grails on Google App Engine Rationale

After test driving Liferay 3 weeks ago, and then trying out Alfresco, I finally got serious about figuring out how best to approach building rich(er) browser based clients, which seems to boil down to which Javascript framework to use. Since the introduction of Google AppEngine support for Java, it occurred to me that one approach worth re-evaluating would be Google Web Toolkit (GWT), which allows you to write client/server apps in Java, and have the client side compiled to Javascript to run on the browser.

When I first heard about this, must be over a year ago, I thought it was a dumb idea. Having struggled since then to attempt to build browser based apps, it is starting to look pretty nice. So nice in fact that I am willing to go back into the Java side of the industry for my consulting practice, after moving away from it several years ago. My complaints at that time were:
1. There are just too many libraries and frameworks that are needed to make a system work
2. Picking the right versions was a dependency nightmare
3. All those libraries required extensive XML configuration
4. Hosting was complex and expensive, making its suitable for high end applications only.

Google's support for Java on App Engine eliminates the last objection for those applications suitable for the Google environment, which includes a number of my clients.

Having made the decision to move back into Java because of GWT, it made sense to try out Google AppEngine/Java as well. So I dutifully went through the excellent tutorials, and found it quite easy to deal with. Then I tried to actually use it to build my own web application. Having worked with several major MVC web application frameworks (Rails, Zend Framework and Catalyst), it was a major disappointment that out of the box, AppEngine doesn't offer an MVC framework for Java. So I started to look around, and explore the Java framework universe. Spring seems to be the most popular (based on shelf space at Barnes & Noble) , but the complexity of attempting to use the Spring stack (including Spring, Spring MCV, Spring Flow..., each with its own book) on AppEngine was starting to make me rethink my decision to move back into Java. That is until I discovered Grails.

Over a year ago, a collegue of mine suggested I take a look at the language Groovy. At the time it didn't seem that robust, and certainly didn't address the web application framework issue. And while Grails did attempt to solve this issue, I thought that it didn't make sense to learn both a new language and a new framework just to write web applications that would only run on high end servers.

So this week I decided it was time to give Groovy/Grails another look since several postings indicated that this now works on AppEngine. I am not going to go into the gory details here, but I can speak from personal experience that it is now possible to build a Grails app, (using JDO instead of Hibernate and GORM), and have it run on Google AppEngine. The benefit is that it takes care of the Java configuration issues mentioned earlier by using Convention over Configuration, and it provides a very capable MVC style web application framework.

The online instructions (http://www.grails.org/plugin/app-engine) and video (http://grails.org/dist/screencasts/grails-appengine-screencast.mov) are excellent , although there are several issues and bugs that I ran into. None of these seem to be show stoppers, but a couple can be major annoyances. Unfortunately that discussion will have to wait that for another day, as well as exploring how to use GWT from Grails. The Google I/O conference (http://code.google.com/events/io) is next week, there should be more information and discussions around these topics there.