Thursday, 20 January 2011

Welcome Grails to your life!

We all know how painful web development in java can be! Maintaing endless configuration xml files, writing hibernate layers & complex build scripts for compiling & packaging can make your experience of developing a web app in java nightmarish. But we would not want to sacrifice the capabilities and power of the Java platform for the sake of ease and agility.

And this is where web frameworks like Grails fit in. These framework take care of the overhead tasks such as configuration, builds, integration, and enable us to concentrate on our business requirement. 
If you are looking for a framework that supports agile development and enables RAD (Rapid application Development), Grails could be your first choice!

Grails is an open source web framework that uses Groovy as it's primary programming language. Grails was inspired by Ruby on Rails, but mainly for java developers. This does not mean, you should not try this framework if you're not from a java background, but Java developers would find themselves productive from day 1.

Features of Grails that enable RAD are:
  1. Convention over Configuration: You don't have to maintain huge complex configuration files to setup your application. Grails uses conventions to determine the role of classes instead the application and how they interact with the each other. 
  2. Groovy: Groovy is a agile dynamic scripting language built on top of the Java language. Groovy code is very similar and much terser than Java, which means almost-zero learning curve, and lesser code to write and maintain. Groovy is a dynamic language, uses meta-programming. And it brings the power of scripting languages to the java world.
  3. Grails doesn't suggest you to use MVC, to forces you to use MVC (which is great, btw!). But using the MVC pattern in Grails is much simpler than in any other web framework. There is absolutely NO need for any configuration. You don’t have to specify in any configuration files which class is a model or a controller, or specify which view file will be used for a certain action. Grails determines all the information by the virtue of the class names and the location of the files.
  4. Code Generation & synthesis: Grails generates considerable amount of code making the process faster and easier for the developer. It not only generates code, but also allows code synthesis. In case of code generation, some bits of code is actually generated on your disk. But in case of code synthesis, the code/feature is available dynamically at runtime. Grails makes use of Groovy's meta-programming capabilities to enable code synthesis. One of the ways in which Grails does this is GORM( Grails Object Relational Mapping) .
If you have a model (M of MVC) class say Author that has fields ‘firstName’, ‘lastName’, grails will add dynamic finder methods that you can use. Eg:-
            Author.findByFirstNameIlikeAndLastName("m%", “Davis”)
  1. DRY (Don't repeat yourself):  Enables you to reuse code as much as possible. It also enables you to reuse java code.
  2. Grails makes use of technologies such as Hibernate, Spring, JDBC, Sitemesh, Ajax. These compoments are already accepted and test technologies, which means strong support and faster development.
  3. GORM (Grails Object Relational Mapping) is Grail’s ORM implementation. But as in case of hibernate, you don’t need to write any hbm configuration files (although you can if you want to) you can also use java for writing your domain classes. GORM provides many dynamic methods that come in very handy and also nearly eliminates the need to know the details of how hibernate works (although I personally believe, it makes a world of a difference if you do), easy way to add validations to your domain object, clear and precise way of specifying the relationship between your domain objects.
  4. Comes with a built-in web server which leads to higher productivity during the development phase.
  5. It has an in-memory database. You can push the choice of a database for your application to as late in the product life cycle as you wish and continue development and testing using the in-memory db.
  6. Building the web-application is as easy as a single command at the command prompt!
  7. It has an extensible plugin system which has lead to strong community support and acceptance. Again, this enables code reuse. There is a sea of plugins to choose from eg. Logging, security, Yahoo UI toolkit etc.
  8.  Good unit, integration and functional testing support.
  9. Most suited for CRUD (create-retrieve-update-delete) type of applications.

I was personally surprised to see the speed at which I was able to come up with a stable application using Grails. If you are using the agile development methodology, you will be able to appreciate the benefits of using Grails. Grails as a technology brings the 'agile methodology' to web-application development. You will be able to reliably and efficiently change an entire functionality or feature in a matter of 2 to 3 days, that you may otherwise take a week in plain java. This enables you to seek  feedback from your customers, quickly implement the changes and get back to them to repeat the cycle. This will lead to increased customer satisfaction & better clarity.

Although the framework does not guarantee a stable and robust application, but surely leaves you enough time and resources to ensure that you can strive for one. So the next time you have to develop an application with stringent time lines, you know what to try ;)

Having said that, you have to TRY it, to believe it.


  1. Good blog, where did you come up with the knowledge in this piece of content? I’m glad I found it though, will be checking back soon to see what other articles you have.

  2. Hey Thanks! I am currently working on an application that's built using grails. Thanks for appreciating.

  3. Nice blog, I want to use GRAG in my project but couldn't find any help on it . Please provide some blog on GRAG plugin to create the domain classes from existing database.

  4. Syntax:
    grails application development

    Excellent Blog,Great Work And Good Posting about Features of Grails that enable RAD.

  5. They are really great tips. Thanks for sharing. I actually enjoyed reading through this posting.

    Web Development India

  6. This comment has been removed by the author.