In association with heise online

03 April 2008, 15:41

Grails and Groovy - The Dynamic Duo for Java

DJ Walker-Morgan

Grails brings all the advantages of Ruby on Rails' fast development to Java, without having to sacrifice any of your existing code.

The loudest quiet revolution in developing applications in recent years is the rise of Ruby On Rails. The combination of Ruby's dynamic language abilities and Rails' "opinionated" framework is very compelling; the almost classic screencast showing in ten minutes how to create a database backed blog with only a command line, text editor and browser is enough to whet anyone's appetite, and an active community around Ruby on Rails makes it a very attractive prospect.

If you have an investment in Java, you may have felt left out of the revolution. This is where Groovy and Grails bring the philosophy and style of Ruby on Rails to Java developers. While development took a long time, Grails has finally reached its 1.0 release.

Creating a Grails application
Creating a Grails application

Grails is built on Groovy, a language which nearly blew up on the launchpad, as it was pushed into the Java standards process early. Since then though it has made solid progress in being a useful dynamic language for Java developers. Its big advantage is that it's tightly integrated with the Java VM, Java language and the surrounding libraries, making it easy to learn and to reuse your Java knowledge without giving up the Java platform. At the same time, it brings dynamic types, closures and useful syntactic sugar to allow you to go from say:

    String[] s={ "a","b","c" }; 
for(int i=0;i<s.size();i++) { System.out.print(s[i]); }


[ "a","b","c" ].each() { print it }

which is remarkably similar to Ruby:

[ "a","b","c" ].each { |x| print x }

It's that similarity, along with many others in design and goals, that got people thinking about implementing a Rails style framework on top of Groovy.

The automatically generated front end for a Grails app
The automatically generated front end for a Grails app

Grails is not a port of Rails though. At first glance, this may be hard to believe. Both do "convention over configuration" style development. "Configuration" is where you start with a bundle of libraries, pick some build tools, work out how to get them to work together and create your own work flow. With "Convention over configuration" you create an "application" which comes complete with a work flow and structure, and you follow that work flow, which goes from creating data classes, controllers and views, through automated testing, all the way to deploying the application.

Print Version | Permalink:
  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit

  • July's Community Calendar

The H Open

The H Security

The H Developer

The H Internet Toolkit