Saturday, 7 November 2009

Deploying Grails application on Google Application Engine

Introduction
Some time ago it was announced that Google Application Engine supports Grails framework. As a great fan of Groovy and Grails I wanted to give it a try. I was also very curious to see how GAE works. In this article I would like to present simple "Hello World" project and its deployment process.

My example uses:
  • Grails 1.1.1 (http://www.grails.org)
  • GAE SDK 1.2.6 for Java (http://code.google.com/intl/pl/appengine/downloads.html#Google_App_Engine_SDK_for_Java)
  • Java 1.6
Configuration
As a first step please download required software and install it. To configure it properly you need to set up:
  • variable GRAILS_HOME to directory where you installed Grails
  • variable APPENGINE_HOME to directory where you installed GAE SDK
  • add GRAILS_HOME\bin directory to PATH variable
Creating GAE account
Go to GAE website (http://appengine.google.com) and create an account. Log in and add new application to your account. Specify application name - I will use "gae-grails-maciek-test".

Creating simple project
Go the your workspace directory and type: grails create-app GoogleGrailsTest
Script should create your project subdirectory - GoogleGrailsTest. You can import your project to Eclipse or another IDE.



Please modify GoogleGrailsTest\grails-app\conf\Config.groovy and add following line:
google.appengine.application="gae-grails-maciek-test"

Of course you should use your GAE application name. Go to project directory and install grails GAE plugin:
grails install-plugin app-engine

You will be asked if you want to use JPA or JDO for persistence. It is not important at all for our case.

To run you project locally on your computer type: grails app-engine run
You should be able to access it at http://localhost:8080



I must confess I noticed a strange stack trace in log files, but application was still running properly...

Deployment
Type:
grails set-version 1
grails app-engine package

First deployment should be done with:
$APPENGINE_HOME/bin/appcfg.cmd update ./target/war

Later when you just update application on GAE sever you can just type:
grails app-engine deploy

During deployment process you will be asked about your google account email and password. I noticed strange bug during authentication process. When script asks you for email just push Enter and go to the next line and enter it there. Password can be entered normally. Without this trick I was not able to authenticate properly.

Now you should be able to access your application at http://your-app-name.appspot.com - in my case on http://gae-grails-maciek-test.appspot.com/

Application can be monitored on GAE pages after logging in to your account:




No comments:

Post a Comment