What are the Grails Advantages over other Java Web Frameworks?

Nowadays there are dozens of Java web frameworks. Many of them serve the same purpose and so I have tried to elaborate just on the most popular and typical in functions ones in my post The Best Java Web Framework.

Although I didn’t seek to cover all the frameworks and mentioned that in the post, there were advisory comments to consider Grails framework in my analysis. Having been given that much respect from the developers, this framework is definitely worth to be given a separate attention.

So please find below an overview of the Grails framework, its advantages and why this framework might be the best for some developers.

Grails is an open source Java framework for creating web applications. Grails is actually built off Groovy which gives the immediate benefit of being more productive. The Groovy syntax is much terser than Java, it’s much easier to do things in one line of Groovy code that would take you several in Java. At the same time Groovy has the capability to work with Java seamlessly, but that’s the different story.

The Grails framework attempts to bring some of the lessons from Ruby on Rails into the Java world such as DRY (Don’t Repeat Yourself) and Convention over Configuration:

– Don’t Repeat Yourself (DRY). Grails enables you to write DRY code and in itself is a good example of how to be DRY. If you have any existing Java code reusing it in Grails should be no problem.
– Convention over configuration. If you adhere to the conventions set out by Grails (which are very sensible btw) you can become productive very quickly.

Grails gets most of its magic from Groovy, a scripting language that is targeted to the JVM and features a mix of static and dynamic typing, and a Java like syntax. Groovy scripts are compiled to Java classes and can import regular Java classes (and vice-versa), so you can leverage your existing libraries.

Grails feels a lot like a Rails framework. If you want experience the power of Rails but don’t feel like learning Ruby then try Grails. On the other hand, if you have spent any time with Rails, you will find Grails simple to learn (especially with a Java background).

GORM (Grails Object Relational Mapping) is used in Grails to map domain objects to their corresponding database table. GORM is written in Groovy, but under the hood, it’s using Hibernate 3. GORM objects look and act very much like Rails’ ActiveRecord objects.There is no explicit mapping required, and table associations are simple method calls inside the domain object (belongsTo(), hasMany(), etc).

Another strong point is the choice. The Java community tends to have an overwhelming number of frameworks, application servers, views (JSP, Velocity, Tag Libraries, etc) and libraries to choose from. While there are pros and cons to having so many options, the bottom line is that you get choice with Grails. Here are a few of them:
– Grails projects are wrapped up as ordinary WAR files, allowing you to deploy them into any J2EE compliant web server.
– Grails uses Hibernate 3 for persistence, but will also support JPA compliant technologies such as EJB3.
– Grails supports both GSP (Groovy Server Pages) and JSP as view technologies.

Community: Grails is targeted at Java developers (a very large community indeed). At the same time it is worth of admiring that the Grails developers weren’t afraid to acknowledge that another community/technology has done something really well.

To sum up here are the main advantages of this framework:
1. Grails is built on several popular frameworks, e.g. SiteMesh, Hibernate,Spring.
2. Java programmers will have a flat learn curve, especially for those familiar with Hibernate and Spring.
3. Grails is maintained by, that means the flexibility and scalability is not just good, it’s great!
4. Grails can be deployed on many popular J2EE servers, e.g. JBoss, Tomcat, WebLogic etc.

Please share your experience of working with this framework. It would be great to hear both positive and negative comments on using it.

Aliona Kavalevich

Aliona Kavalevich

Business Development Manager

Skype: aliona_kavalevich
LI Profile: Aliona Kavalevich

13 thoughts on “What are the Grails Advantages over other Java Web Frameworks?”

  1. I’ve used both Rails as well as Grails and I definitely prefer Grails. I would disagree with a statement from the article though, namely that GORM objects look and act very much like Rails’ ActiveRecord objects – the persistence concept used in the two is different, even though on the surface they may seem identical.

  2. I like using Grails for small projects where memory consumption, performance, scalability, typesafety,….. is not important, perfect. But you can run into a lot of problems, when you have to deal with large projects. Transactional-nightmare, GORM eats memory using large datasets(reading and writing 10 GB from/into database is not trivial, but should be), …

  3. I have used spring MVC and hibernate for years. Grails seemed to take the best practices – especially for spring MVC – and make them so much simpler. I built several websites, and commercial projects using grails. Grails was especially useful for projects that needed to be done under a time constraint, or for a MVP (Minimum Viable Product) type project. I still have some reservations about GORM – mostly from a performance perspective.

  4. GORM supports almost all datastores, from the Spring-Data-Project via Plugins. Therefore ist’s more a loose “contract” as how persistence should happen following the Active-Record-Pattern. If you ever wanted to map an Domain-Object to different datastores simultaneously (or some Objects to Mongo, some to SQL, some to Redis) you can’t beat GORM! (However in the standard JPA/hibernate case there are some gotchas.)

  5. grails lets you to concentrate on what you want to achieve , not how to config your project (jars, complex xml configuration like seam)

  6. I used Rails over more years and now working on grails. But I feel grails community is not that active and maintained as Rails community despite technology comparisions.
    Rails has enormous community like railscasts, toolbox, github and more gems.
    Grails we need to add plugins and there are very less and stable plugins.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s