Rails vs. Grails vs. Helma: The JVM Web Framework Smackdown, Part 1

It's the ultimate JVM Web Framework Smackdown! Three will enter the cage. Only one will exit the victor. Will it be JRuby on Rails? Groovy on Grails? Or Helma?

Before the advent of Ruby on Rails, many Web developers worked with Perl or vanilla PHP. Perl’s legacy dated back to the earliest dynamic Web sites. In heady days, the “Perl Mongers” were active proponents and evangelists, and the community nurtured and maintained a vast repository of contributed code. PHP was simple to learn, a snap to deploy and host on virtually any platform, and thus quickly earned a devout following. Indeed, both languages grew popular because it was easy to start an application. However, as Perl and PHP applications grew, developers inevitably became tangled in a mess of code.

Other developers eschewed scripting languages and opted for more heavyweight Web frameworks, especially those written in Java. Applications written in Java were bullet-proof and backed by a rich set of libraries, but were far from perfect, too. Java frameworks exacted a high price, miring developers in the pits of XML hell. While the Java frameworks scaled well, the initial inertia left many Java web developers jealous of the rapid, early progress Perl and PHP developers enjoyed.

Ruby on Rails, to a large degree, delivered the best of both worlds. Rails featured a well-thought out organization that guided developers toward a clean MVC design, and through a philosophy of Convention over configuration, developing new applications was only marginally more difficult than with straight PHP. Web developers, it seemed, could finally have it both ways.

But the story does not end with the advent of Rails. More and more sites began to use Rails, but as several endeavors became successful, developers also ran into new challenges. Twitter gained notoriety when the company moved part of its architecture to Scala. And, despite the benefits of Rails, many developers have begun to miss the wealth of libraries and tools commonly found with Java.

Fortunately, several Java frameworks now combine ease and robustness. Relying on JVM scripting languages and the Rails philosophy of convention over configuration, these new frameworks provide the flexibility of Rails and the enterprise-worthy support of Java. This article compares three of the most promising modern Java frameworks: JRuby on Rails (JRoR); Grails, powered by Groovy; and Helma, with Rhino JavaScript.

The Sample Application: PenguinMusic

To test JRoR, Grails, and Helma, let’s build a music site from scratch with each framework. The sample site, PenguinMusic (shown), allows users to browse songs ordered by popularity, view details about an artist and album, and leave comments if logged in to the application. The application also handles user registration.

While this sample application does not take advantage of all the bells and whistles each framework offers, it does focus on a core subset of features that virtually every website must provide, including database interaction, user authentication, and form handling. The sample code also looks at automated testing and site administration to some extent. However, no attempt is made to build facilities for Ajax or address performance. Not every site needs Ajax support, and all these frameworks have at least adequate performance for the bulk of Web applications. The focus here is the ease of launching a new application.

Each of the three frameworks ships with an embedded databases, but odds are MySQL is your choice for a production database, so that’s what’s demonstrated here. However, since all the candidate frameworks rely on JDBC, you can interact with just about any major database engine.

If you would lke to follow along, you can download the source code for each implementation. Additionally, there are some helpful scripts to load test data for each of the database setups.

JRuby on Rails: The Classic, Now Playing at Your Local JVM

If you want the benefit of a Ruby on Rails-like framework for the JVM, one obvious option is, well, Ruby on Rails. The JRuby team has been focused on Rails from the beginning, and with JRuby 1.0, the team finally achieved full Rails compatibility. Performance was terrible initially, but the developers have done a great deal of work since and more recent versions are quite fast.

The source code for the JRuby on Rails implementation of PenginMusic can be downloaded here.

Getting Started with Rails, the JRuby Way

Installing JRuby on Rails is only a little more complicated than installing traditional Rails. You must download Gems and install it with JRuby and install the requisite libraries. The command to use is:

 $ jruby -S gem install mongrel activerecord-jdbcmysql-adapter rails

Running jruby -S rails jrorPM -d mysql creates a new application named jrorPM based on MySQL. After the initial code generation, your first task is to edit config/database.yml to match your database configuration. In particular, you must specify jdbcmysql as the adapter.

  adapter: jdbcmysql
  encoding: utf8
  reconnect: false
  database: jrorPM_development
  pool: 5
  username: root
  socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
  adapter: jdbcmysql
  encoding: utf8
  reconnect: false
  database: jrorPM_test
  pool: 5
  username: root
  socket: /tmp/mysql.sock

  adapter: jdbcmysql
  encoding: utf8
  reconnect: false
  database: jrorPM_production
  pool: 5
  username: root
  socket: /tmp/mysql.sock

Once the database has been configured, jruby -S rake db:create:all initializes the database, and jruby script/server starts the application.

Rails Models and Migrations

One of the hallmarks of Rails implementations is that the structure of the data model lives solely in the database. This avoids any repetition of logic, a core tenet of Rails’s Don’t Repeat Yourself (DRY) philosophy. However, most of the validation logic lives in the Ruby models. As a result, one must switch between the database table and the Ruby class to get a complete picture of the model. However, this is a relatively minor hindrance, as the strong connection between the database and the model class is one of Rails’s greatest strengths.

Once upon a time, Rails developers used SQL to create models, but the practice has gradually fallen out of favor. Today, developers are encouraged to use migrations instead. Migrations are Ruby scripts that create or update a database schema. A migration is also database-independent and is fairly straightforward to use. Migrations also offer an important advantage: versioning. Historically, tying a database version to a code version has been problematic. Migrations offer a solution.

However, migrations can also be brittle. If there is a problem in any of the migration scripts, the database can become stuck in an unusable state, forcing you to resort to SQL to fix the problem anyway. Migrations also are noticeably lacking in features. For instance, foreign key constraints are not available without a plugin.

SQL does provide fine-grained control and is an option with Rails, although you may be heckled by some Rails fanatics if you choose to use it. Here, let’s stick with migrations since they are the more conventional approach.

The Rails generate script creates new models and other components from the command line. Specify model as the first argument if you just want to create the required model class. More often than not, though, you’ll want to specify scaffold instead to generate a model and complementary administrative pages to create, edit, and delete records. The second argument to generate is your model name, and the remaining arguments are name:type pairs, one pair per field. (You can actually omit all of the fields and manually edit the migration script yourself if you prefer.)

To generate the code for the Song model and scaffold, the command is:

$ jruby script/generate scaffold song name:string album_id:integer \
  track_num:integer playlist_url:string duration_in_seconds:string \

The command creates a file named db/migrate/*_create_songs.rb (the * is a serialized value that orders the migrations in a sequence) with the following contents:

class CreateSongs < ActiveRecord::Migration
  def self.up
    create_table :songs do |t|
      t.string :name
      t.integer :album_id
      t.integer :track_num
      t.string :playlist_url
      t.string :duration_in_seconds
      t.integer :num_downloads


  def self.down
    drop_table :songs

Although you can use this migration as-is, let’s modify the code to improve the database representation. Let’s make album_id and name required fields and let’s assign a default value for num_downloads. This requires changes to three lines:

      t.string :name, :null=>false
      t.integer :album_id, :null=>false
      t.integer :num_downloads, :default=>0

The process is repeated for the other models, followed by a database update:

$ jruby script/generate scaffold album artist_id:integer genre_id:integer \
  title:string public_id:string url:string album_cover_url:string \
  album_cover_name:string price:float blurb:text
$ jruby script/generate scaffold artist name:string url:string
$ jruby script/generate scaffold genre name:string code:string
$ jruby script/generate scaffold user username:string \
  password:string email:string admin:boolean
$ jruby script/generate scaffold comment user_id:integer album_id:integer \
  title:string body:text post_date:datetime
$ jruby -S rake db:migrate

As a final step, the models must be tied together. This is done through the has_one, has_many, belongs_to, and the concisely named has_and_belongs_to_many functions.
As an example, here is the model class for Album:

class Album < ActiveRecord::Base
  belongs_to :artist
  belongs_to :genre
  has_many :songs
  has_many :comments

Comments on "Rails vs. Grails vs. Helma: The JVM Web Framework Smackdown, Part 1"

Discover ways to obtain females to speak to you on the internet and start discussions that end in days.

my homepage – trade ex insurance phone number

Pretty! This has been a really wonderful article.

Thank you for providing this info.

Also visit my webpage :: ga board of pharmacy

The premium for ‘own harm’ cover, which develops the bigger piece of the
traders insurance for 18 year olds (Dannie) premium, is based upon danger as well as affordable tensions.

You could nonetheless request for add-ons to your policy to enable you to drive these automobiles.

my web site :: http://jabaoo.com/?document_srl=294118

Click onto the Our operation” section as well as in the 300 words utilized to explain the Saga brand today” motor trade
insurance quotes online
is not stated as soon as.

Whether you are getting new motor trade insurance (toplista.4gr.pl) policy
or renewing your plan, you should consistently search for offers first.

We analyze the whole plan and also look for to balance
and offer effect to all provisions so that none will certainly be useless or inoperative.

My blog :: http://www.brewwebsolutions.com/index.php/component/k2/item/3-a-journey-through-beautiful-typography-in-web-design.html?limitstart=0

I am extremely certain this van price greater than the
$30 a day that Ford was paying, but they didn’t demand me anything.

Feel free to surf to my page; traders insurance 21 year old – http://www.rkstudio.it/faq/item/125-con-quali-software-lavorate?g2_returnName=Album3Eknowing,

To consult with an electric motor field expert call 0161 874 4157 or click on this link for an on-line quotation.

My blog post http://www.parhambon.com/parhambon/index.php/fa/component/k2/item/7-sentence1

It permits the qualified drivers to drive any type of motor
vehicle for the purposes of their motor trade insurance
21 (Liam) trade business.

Take into consideration going via your insurance company to deal with
the car if significant damages was suffered as a result of a crash.

Also visit my page – http://www.faircasinos.com/forum/kb.php/templates/emoticons/kb.php?mode=post_comment&item_id=9&cat_id=3&cid=141%3Ejay%20z

Find out ways to obtain ladies to speak to you on the internet and begin chats that end in days.

Take a look at my weblog – traders insurance (http://nogteff.kiev.ua)

Buying and selling automobiles at on-line public auctions
such as ebay.com is coming to be significantly popular.

My blog trade insurance road tax

Whether you have a little fleet of 2 or 3 automobiles or a bigger fleet we could arrange
a policy that will certainly supply the right option for your business.

Also visit my web-site: traders insurance number

The Pentagon strategies to obtain about 2,400 of the radar-evading
F-35s in coming years, at an expense of greater than $400 billion.

Also visit my webpage … http://dibamandegar.ir/index.php/fa/component/k2/item/28-oil?limitstart=0

Roadway Threats Insurance policy – To cover car whilst being utilized
on the general public roadway, a legal services demand
under the Roadway Web traffic Acts.

My web blog: http://compninja.com/modules.php?name=Your_Account&op=userinfo&username=FinnBeor0

Sometimes it corrects to follow the market as well as rate near limited cost to fill the

Feel free to visit my webpage – motor trade insurance companies, blog.breathelikeafish.com,

Unaccompanied demonstration could only be provided on licensed vehicles, supplied your insurance coverage
is prolonged appropriately.

my web blog http://ankarakombi.net/index.php?option=com_easybookreloaded&

The Court discovers that the Plan unambiguously prevents any sort of as well
as all suits started more than 2 years after the date of the damages or loss.

Here is my page – http://sociedadasturianadefilosofia.org/historiadelafilosofia/index.php?title=10_Detroit_Charities_Serving_Their_City_Amidst_Insolvency_News.

To be able to trade legitimately, electric motor traders insurance
(http://riddimnrhymes.com) should have insurance cover in position when driving their consumers’ cars
when driving.

A gasoline-only car that obtains 25 mpg yields an average yearly energy cost of $1,650.

Also visit my page; traders insurance for 18 year olds [http://www.pluriball-italia.it]

A weakness is that it does not utilize the most approximately date information to recognize current loss cost

Feel free to surf to my blog post … traders insurance (thietkexaydungthanhhoa.com.vn)

Nash Warren provided me with a degree of solution I have actually not received before by any
other traders insurance contact number, Larhonda,
policy business I have actually handled.

Electric motor Profession Insurance could only be obtained for
customers working in the Motor Profession and
proof of trading may be called for.

Also visit my page … http://jvlosguerreros.cl/primera-asamblea-general?page=8

Therefore you will certainly need to speak with an expert in motor profession traders insurance rules under 25
to access the very best prices with in the sector.

Here you’ll find a few ways to lower expense on the
purchase of a major home appliance.

Visit my web blog; motor trade insurance cost (http://radiotop.mlrserver.de/)

Very good blog you have here but I was curious if you
knew of any user discussion forums that cover the same topics talked about
in this article? I’d really like to be a part of group where I
can get opinions from other experienced individuals that share the same interest.

If you have any recommendations, please let me know.

Thank you!

My web site … elite dangerous billigflieger Hamburg

The main description of a Category D vehicle
is one that has actually suffered mishap harm
that would set you back less to mend compared to its value.

Look into my site; motor trade insurance part time –

Investors traders insurance number; 020tiein.com,
varies from normal cover as it offers security for any sort of car within your
belongings at the time.

The most effective means is to select a more standard plan, yet this
likewise simply supplies fundamental cover
and also a fully thorough plan may not be far more.

My homepage – trade travel insurance

The quote is after that based upon this tailored policy,
so you only pay for the specific plan attributes you need
- no fluffy extras.

my site; traders insurance claims

Always a major fan of linking to bloggers that I enjoy but do not get a lot of link enjoy from.

Why viewers still use to read news papers when in this technological world everything is accessible on web?

My site – wedgewood pharmacy

I vusited multiple sites but the audio feature for audio sonts existing at this site is genbuinely wonderful.

my blog post – kroger pharmacy hours

Fantastic site. Loots of helpful info here. I am sending it to several
pals ans additionally sharing in delicious. And naturally, thank you
in your sweat!

Alsso visiit mmy webpage savon pharmacy

of course like your wweb site but you have to take a look att the spelling on several
of your posts. Several of therm are rife with spelling prohlems and I in finding it
very bothersome to inform the reality however I will surely come again again.

Look into my website cvs pharmacy application

Everyone loves what you guys tend to bee up too. Succh clever work and coverage!
Keep up the amazing works guys I’ve added you guys to blogroll.

My homepage; idaho board of pharmacy

Hmm is anyone else having problems with the images on this blog loading?
I’m trying to figure out if its a problem on my end or if it’s the blog.
Any responses would be greatly appreciated.

Saved as a favorite, I like ypur blog!

Here is my blog post :: arkansas state board of pharmacy

Hello there! This post could not be written any better!
Reading through this post reminds me of my previous room mate!

He always kept talking about this. I will forward this write-up to him.
Pretty sure he will have a good read. Many thanks
for sharing!

I’ve been browsing online greater than three hours lately,
but I never discovered any attention-grabbing article like yours.

It’s beautiful value sufficient for me. Personally, if all website owners and bloggers made
excellent content material as you probably did, the internet will be much more useful than ever

I really enjoy the blog. Fantastic.

This is a topic that’s close to my heart… Thank you!
Exactly where are your contact details though?

She wants to get her kids but again she’s no insurance and can’t pay the condition system which costs
$75 per child per month.

My blog post – http://agilekorea.herokuapp.com/event/2012/post/41?q=node/add/

You will find prospects that you simply wish to select an additional health-insurance plan for them as
the group medical insurance companies – cncwiki.info – techniques proceed suprisingly low on dependents and parents.

The scientific development brought forth by technology in this 21st century, has been noticed in the area of the health care market also.

My blog post … http://wiki.wein-fulda.com/index.php?title=Leisure_Ten_Benefits_Of_Class

Consider this: your’s chances could be less than the possibility
you will be hit by lightning, which is 1 000, in 700.

Also visit my web blog http://social.originalgamercrew.com/profile/FredricSuf

In Georgia, there are eight significant insurance companies that might must
contribute to a Georgia medical insurance singapore – Randal, pool.

I am extremely impressed with your writing skills and also with
the layout on your weblog. Is this a paid theme or did you customize it yourself?
Anyway keep up the excellent quality writing, it’s rare to see a great blog like this one nowadays.

Here is my homepage :: cialis without a doctor

Leave a Reply