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 SpringSource.com, 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.
Business Development Manager