Grails on Google App Engine – Part 2: Project Setup

October 17, 2010 at 5:09 pm | Posted in GAE, Grails, Groovy, Java, Web | 4 Comments
Tags: , , , , , , , ,

Setting up Grails for App Engine on my favorite IDE IntelliJ was as easy as installing the App Engine plugin. At the time of writing the latest plugin version is 0.8.10. It is by far not free of bugs but gets you where you want. It provides you with the basic setup to build, run and deploy your project in your development environment. The plugin was fully compatible with Grails 1.3.1. I didn’t try out to upgrade my project to the latest version of Grails yet. Stick to the plugin documentation to get the basic setup going. To be able to reference the GAE/J classes I dropped in the JAR files appengine-api-1.0-sdk-1.3.7.jar and jdo2-api-2.3-eb.jar into my project’s lib directory. It was extremely helpful to set up Log4J correctly right away. Earlier versions of the plugin had some Log4J-related bugs but they seem to be fixed now. Here’s an excerpt of my Config.groovy:

log4j = {
   appenders {
      console name:'stdout', layout:pattern(conversionPattern: '%d{dd MMM yyyy HH:mm:ss,SSS} [%t] %-5p %c{2} - %m%n')
   }

   debug  'grails.app', 'com.favalike'
   ...
}

The plugin still has a bug related to i18n. In case you’re using one of the messages.properties files to store internalized texts that would leave these files empty after building the WAR file. I could still make it work by applying the workaround described in the JIRA ticket. You got to change your Bootstrap.groovy as follows and build your WAR file for production environment: grails -Dgrails.env=production app-engine package.

import grails.util.Environment

class BootStrap {
   def messageSource

   def init = { servletContext ->
      if(Environment.getCurrent() == Environment.PRODUCTION) {
         messageSource.basenames = ['WEB-INF/grails-app/i18n/messages']
         messageSource.clearCache()
      }
   }

   def destroy = {
   }
} 

To improve performance from the get go I made sure I had precompilation enabled. Furthermore, static files can get served by dedicated servers and caches. Both settings are made in appengine-web.xml.

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
   ...
   <precompilation-enabled>true</precompilation-enabled>
   <static-files>
      <include path="/favicon.ico" />
      <include path="/css/**.css" />
      <include path="/images/**.*" />
      <include path="/js/**.js" expiration="1d" />    
   </static-files>
</appengine-web-app>

More on this topic:

Advertisements

4 Comments »

RSS feed for comments on this post. TrackBack URI

  1. […] Grails on Google App Engine – Part 2: Project Setup […]

  2. […] Grails on Google App Engine – Part 2: Project Setup […]

  3. […] Grails on Google App Engine – Part 2: Project Setup […]

  4. […] Grails on Google App Engine – Part 2: Project Setup […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: