Grails vs JRuby on Rails - recent developments

For Java Platform, JRuby on Rails and Grails are two leading Agile frameworks based on dynamic languages Ruby and Groovy. Easy development with Rails and Efficient deployment on Java Platform" is the force behind the momentum JRuby on Rails has gained. We saw earlier in our articles, that the reason for the growth of JRuby on Rails is the desire to utilize the productivity of Rails in development and the efficiency of multi-threaded servlet technology in deployment and make use the host of other services, the Java Enterprise stack provides. The support of Sun has also played a role. NetBeans6 has become one of the popular Ruby IDEs and now NetBeans6.5 comes with open source Glassfish v3 Prelude wherein you can deploy Rails and Grails applications easily (we will see about this later.) The commercial Sun Glassfish Enterprise Server v3 Prelude will provide enterprise support for the above applications. Realizing the growing importance of dynamic languages and their Agile frameworks, SpringSource, the company providing commercial support for Spring applications has acquired G2One the company behind Grails. Rod Johnson explains the motive of acquisition in the following words:
"we do see a growth of interest in dynamic languages. We think that's a pretty broad movement across the IT industry. You are seeing a significant number of people who like dynamic languages. We are still, of course, completely committed to providing excellent solutions around Java but we want to make sure that we can reach out to those - that audience and let them rate the full benefits of Spring…Grails is a technology that is built on Spring. Grails is built on Spring, it is a technology that really enables people who prefer dynamic languages to enjoy that experience but do so in a way that gives me full access to the benefits of the Spring component model and all that Enterprise Java has to offer"

Spring has been a significant force in Java since Rod Johnson wrote Expert One-on-One J2EE Design and Development in 2002. This book was a rallying call for Java developers who were fed up with the overly complex EJB specifications emerging from Sun Microsystems in the early part of this decade. Since 2002, Spring has become the center of Java innovation, and in conferences like JavaOne, it is clear that most server-side Java developers look to technologies like Spring and Hibernate before they look to many of the standards emerging from the JCP or from Sun. Grails is meant for those who want to develop using Spring with "convention over configuration paradigm" and without the botheration of writing the XML configuration files or Annotations

Rod Johnson also compared Rails and Grails in the following words:

"I think certainly if you look at Ruby on Rails, Rails introduced a number of very interesting ideas. For example, the extensive use of convention over the configuration, the kind of productivity and scaffolding tools that they provide. All of that is very interesting. So that certainly was a positive side. On the negative side there are really a number of things that are highly problematic for Enterprise developers looking to build applications in Rails.
Firstly, ActiveRecord really lacks the scalability and sophistication of our mapping solutions in Java. That is something that is absolutely not a problem for Grails. Grails can leverage the best that is available in Java or mapping. Secondly, as Graeme's already alluded to the performance benefits. Thirdly, if you are building an application with Ruby on Rails and you encountered the scalability issues, if you encountered the limitations of active record, if you encountered the problems of conversational state management, if you encounter a significantly to access Enterprise libraries that you already have authored in Java, you have to go rewrite your app. You're going to have to go rewrite your app in Java…secondly if you ever need to write something in Java or if you ever need to use the full power of Spring you just go do that and you do that within your same application. There is absolutely no impedance mismatch, no jump into a different technology. So we feel that Grails is the technology that really picks up on a lot of the benefits that Rails delivered but he's actually much more Enterprise ready."

If number of downloads is an indication, the many downloads of Glassfish v3 Prelude show that JRuby on Rails is gaining ground. And NetBens6.5 provides integrated tooling (develop/deploy/debug) cycle for Rails applications and it gives impetus to the growing use of Rails . A year ago Grail's downloads were running around 7,000 per month, now they've been steadily growing to an excess of 70,000 per month. That not only is truly explosive growth but it means that Grails has one of the largest communities out there in terms of Enterprise Java.

With the above notes on the latest developments in the race between JRuby on Rails and Grails, we can see a Grails application that makes use of one to many association- the same Blog we used in our article "ACTIVERECORD ASSOCIATIONS-With NetBeans" in the July 2008 issue of DeveloperIQ ".You can see that the Rails application, using the above association, required more code from us .We had not only to declare the association in the model class but also to make necessary modification to the framework- generated controller and view classes. Since Grails follows naked object pattern it is enough if you declare the association in the domain classes and the framework will use it not only for persisting to the database but also for generation of controller and view codes.

  Please see the article “Setting Up Development Environment For Grails on Windows Vista_XP.htm” available on to set up the Grails environment.   Go to the directory you created for Grails projects -in our case C:\grails-projects- in the command prompt. Type “grails create-app Blog”. The  necessary directory structure will be created. Change to your Blog directory and create two domain classes Comment and Post by typing “grails generate-domain-class Comment” and “grails generate-domain class Post”. The stub of the domain classes will be created in the folder C:\grails-projects\Blog\grails-app\domain .Open them with your text editor –I use JCreator - and fill up the code as follows:

class Comment
String comment
Post post
def belongsTo = Post


class Post
String title
String body
static constraints = {
def relatesToMany = [ comment:Comment]
Set comments = new HashSet()


Now You can use the command  “ grails generate-all”. You will be prompted for domain class name.Give the name Post.Use the command “grails generate-all” once again. This time for the prompt give the domain class name Comment”. Now the application is ready for running. With the command “grails run-app”. You can go to your browser and type in the navigation bar http://localhost:8080/Blog

You will get Figure 1. If you click PostController  and New Post you will be prompted for Title and Body and Id will be filled up by the framework  After you created a post the Browser will be as in Figure 2.If You don’t fill up Title or  Body you will get an error message as in Figure 3.You can click Home and click CommentController and New comment .You can choose the ID of the post for which Comment is created from the option pane and fill the comment. After you fill up the comment your browser may look as in Figure-5

Seeing the above You will agree that that there is no easier way to create a Blog  than in Grails .At the same, as Rod Johnson pointed out You can also directly code in Java or Spring  in the same application, if  there is need for it. You know, Spring IOC has become the de-facto standard for the middle tier and same can not be said about Spring MVC, as Struts dominates presentation tier. Probably Grails which is built on Spring  may help them to gain market share in the presentation tier also.