Imagine a bacon-wrapped Ferrari. Still not better than our free technical reports.
See all our reports

The Curious Coder’s Guide to Java Web Frameworks: Grails

Get the full report

Psst! Want to see the 8 most popular Java Web Frameworks compared? Since this post here, we’ve made The Curious Coder’s Java Web Frameworks Comparison: Spring MVC, Grails, Vaadin, GWT, Wicket, Play, Struts and JSF. Grab the complete report in HTML and/or PDF. Win!

Dude, go for the Full Report instead!

This is the second post in our review of Java web frameworks (last week we covered Vaadin). Today’s hero is Grails, a web framework by Pivotal, who is also responsible for Spring Framework and a bunch of other valuable technologies. Grails accounts for 7% of all Java Developers according to our Developer Productivity report.


Framework Description

Grails is a full stack framework. It is not just an MVC, but also includes ORM, GSP view technology and a build system. According to the official website:

Grails is an Open Source, full stack, web application framework for the JVM. It takes advantage of the Groovy programming language and convention over configuration to provide a productive and stream-lined development experience.

I want it! How can I get it?

Obviously, you go to the website and download the latest version (2.2.2 for me) Grails comes with a console – just like Play! or Ruby on Rails. Using this console you can create a project (creates directory structure and configuration files, installs the default plugins), start the application (uses Apache Tomcat/7.0.39) and create scaffolds for a lot of classes: domain model, controller, service etc. It does not feel like a classical Java enterprisey development. There is a Grails plugin for Eclipse, IDEA and NetBeans. Tooling includes some fancy features, such as jumping from a class to a corresponding service/controller/domain class. Console can also be integrated into the IDE.

To start using Grails you also need to learn Groovy, so it’s two new technologies for most of the new users. The good thing about Groovy is that it’s nearly a superset of Java language, i.e., almost any valid Java code is also valid Groovy code. If you don’t know how to write something in Groovy – write it in Java.

Grails comes with a reloading mechanism out of the box, but it has some limitations and you may still want to use JRebel if a part of your project is in Java.

Grails in action

After installing Grails and an Eclipse plugin I have created a new Grails project. The actual creation is delegated to the Grails console. After this is done you can already run the project from within Eclipse and see the Grails welcome screen with the application status, installed plugins and available controllers. Right click on the project – Grails Tools – and you can create a whole bunch of stuff using scaffolding. Lets create a domain class Rebel and add two fields: String name and Integer redeploysPrevented. Next step is generating the view and controller which is done by a single command which takes a fully-qualified name of the domain class as an input. Here is an extract from the generated controller:

class RebelController {

  static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

  def index() {
    redirect(action: "list", params: params)

  def list(Integer max) {
    params.max = Math.min(max ?: 10, 100)
    [rebelInstanceList: Rebel.list(params), rebelInstanceTotal: Rebel.count()]

  def create() {
    [rebelInstance: new Rebel(params)]

  def save() {
    def rebelInstance = new Rebel(params)
      if (! true)) {
        render(view: "create", model: [rebelInstance: rebelInstance])

    flash.message = message(code: 'default.created.message', args: [message(code: 'rebel.label', default: 'Rebel'),])
    redirect(action: "show", id:

Now lets look at an extract from the generated GSP:

  <div id="list-rebel" class="content scaffold-list" role="main">
    <h1><g:message code="default.list.label" args="[entityName]" /></h1>
    <g:if test="${flash.message}">
      <div class="message" role="status">${flash.message}</div>
          <g:sortableColumn property="name" title="${message(code: '', default: 'Name')}" />
          <g:sortableColumn property="redeploysPrevented" title="${message(code: 'rebel.redeploysPrevented.label', default: 'Redeploys Prevented')}" />
        <g:each in="${rebelInstanceList}" status="i" var="rebelInstance">
          <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
            <td><g:link action="show" id="${}">${fieldValue(bean: rebelInstance, field: "name")}</g:link></td>
            <td>${fieldValue(bean: rebelInstance, field: "redeploysPrevented")}</td>
    <div class="pagination">
      <g:paginate total="${rebelInstanceTotal}" />

As you may note, the main difference from JSP is the default Groovy taglib with g namespace and the Groovyfied EL.

If you want to understand more Groovy take a look at our review of Groovy in our Adventurous developers guide series.

A test class with 8 fully functional unit tests will be also autogenerated. A link to the controller appears on the main page and we can already perform CRUD operations. This scaffolding can even deal with one-to-many, but not many-to-many relationships.

What if we need something more complicated in the UI? Then either create it yourself in GSP with a possible addition of Javascript or find a specific plugin, that will do your job for you. Plugin manager is also available from IDE.


Decided to add authentication with Spring Security? Or started using some NoSQL solution like MongoDB or Neo4j? Or want to add caching capabilities? There is a plugin for that! Actually a lot of them (OVER 900): Plugins provide a Groovy API for a lot of well-known Java libraries. And they are super easy to install – just add compile ":lib_name:lib_version" line to your build script.

What’s under the covers?

Grails’ MVC functionality is covered by Spring MVC, GORM is actually a facade for Hibernate. Both of the technologies are very mature and functionality-rich, thus one may assume that Grails user will also benefit from them while enjoying the simplicity provided by Groovy. Groovy’s build system Gant is a Groovyfied version of Ant and GSP’s are Groovyfied versions of JSP’s.

My Feelings about it

Grails’ simplicity rocks. Next time I will need to implement some small-to-medium CRUD application I will consider using Grails. The setup is very fast and scaffolding saves a lot of time. But once you need to implement something more complex, it is questionable, whether I would recommend Grails. On one hand Grails have powerful Spring and Hibernate under cover. On the other hand – will Grails make it more simple to implement a huge project or will it just just add another layer of abstraction which may cause some problems itself. Need to try before answering this question. That’s why we ask you, Grails users to share your thoughts in the comments.

Want to know more?

There is a huge amount of information out there. Documentation section is actually a wiki, which can be modified by any logged in user It has an official manual, tutorials, screencasts, a sample app and more. If that is not enough, then look through the mailing list or search through nearly 12k grails-tagged questions on SO

What does it cost?

Grails is free and open-source, though you can buy enterprise customer support or consulting services from Pivotal.

How can I contribute?

You can raise and review issues in JIRA, edit wiki and the user guide, provide code fixes and create plugins.

  • Angel

    Hi, I currently own a JRebel licence but since I moved to Grails, 6 months ago, I don’t put it to much use to be honest, so I am seriously considering not renewing my licence next time since it is a lot more expensive and I am not getting much benefits from it now. Are you guys thinking of a way to leverage your product to provide Grails support to enhance its hot swap features? If notn I am afraid you will see a drop in licence numbers unfortunately.

  • arhan

    If you could describe what are the use cases for JRebel with Grails (and what version of it) – that would be a great input. So far, there isn’t much to support for us in Grails and it is definitely not high on our list.

    If you feel that Grails makes you more productive and you can benefit form leveraging this framework – that is great!

  • Excellent intro, just a few remarks:

    * latest Grails release is 2.2.3; a must have if you’re running jdk7u25. See
    * There’s great support for Grails in all major IDEs. Eclipse is not a *must* in order to develop Grails applications. You can even use text editors such as TextMate, Sublime Text, or my personal favorite: Vim.
    * There’s no need to generate controller and views If relying on default behavior, just scaffold everything and customize as needed

  • Ross Oreto

    Grails does have its own hatswap capability however its not very good and I have to restart half the time. If JRebel actually improved that hotswapping and made it reliable, there is a lot of value there since I think many grails users would want this functionality. Grails is also a growing java web framework, so it could really help expose your product more by supporting grails. I for one would be really interested in jrebel+grails since I do a grotesque amount of restarting on most days.

  • arhan

    Ross, thank you for you feedback.