Running Rails 3 on JRuby in Windows

I read an excellent post today, that resonated with me.

My day job involves me using ColdFusion (CF), a interpreted language on the JVM. Say what you will about CF as a language, but the decision they made at version 6 back in 2002 to rewrite CF to run on the JVM was inspired. It brought some real stability and power to the CF platform, and we’ve benefited from this deep integration with Java since then. We get all the speed of CF development and all the power of the JVM, and we get the seamlessly integrate with a myriad of different Java libraries. We can use any JVM debugging tools out there to find issues with our applications, and we can run CF on almost any major platform, should we wish to.

However, as a scripting language, CF can be inconsistent. It lacks any form of null value for instance which can be pretty frustrating in mapping database tables to CF objects. It’s case insensitive which in an unsupervised environment can make things very messy if developer are not consistent. While the syntax is much more compact than Java, it is not very expressive by modern standards, is full of global functions len(), listFindNoCase() and the implementation of the tag and script versions of the language can be confusing and inconsistent. Nevertheless we use it, it’s always been up to the job and overall it’s an enjoyable and productive language to work with.

In my spare time I’ve dabbled in PHP, Python and Groovy (Grails). And lately I’ve been playing around a lot with Ruby on Rails. I really like the Ruby language and the Rails framework is really excellent. But then again Rails is a very popular framework and Ruby a very popular language compared to CF. If we take the number of questions asked on Stackoverflow.com as an indication of the number of programmers using a particular language then we can really see the difference:

Ruby on Rails – 45854
ColdFusion – 2534

But before I go on: an admission. I tried to dabble in Rails a few years back (maybe 2006) before I really understood Ruby, and I did it in a Windows environment as I did not have a Mac at the time. Boy was that painful on both counts. However, in the past 6 months I have taken the plunge and invested in a Macbook Pro and all of a sudden, after reading a few Ruby tutorials before going near Rails, the penny dropped. Programming using Ruby on Rails on a Mac is a dream. Everything works. It’s really great.

Addiitonally the deployment setup for Rails is great, and I’ve had a really easy time deploying to Heroku.

Which brings me back to the article I mentioned at the start. The gist is that Ruby developers need to start making life easier for those on Windows, and if they do that they will be rewarded by an explosion in users, because until recently Ruby and Rails is for the Mac and Linux crowds only.

That was until JRuby arrived on the scene.

Now Windows developers can run Ruby on the JVM, very much like the way CF works now. This not only opens up Ruby and Rails to Windows developers but also to the ‘enterprise’ crowd, the developers who are using Java now but crave a performat scripting language with lot of programmers using it. With JRuby they can have the JVM, they can have native threading and real concurrency, and they can all their usual JVM tools but they also have a massively popular, modern language and framework which should make them more productive.

As an experiment his evening I decided to see if I could get my spare-time Rails application – currently running on my Macbook Pro and in the Heroku Cloud – up and running on my Windows 7 laptop using JRuby.

I was actually very surprised at the results. It was very simple. The steps are simply to:

  • Install JRuby + JVM (single Windows installer)
  • Follow these instructions but just to get rails and the ActiveRecord / SQLite adaptor gem installed
  • I then had to tweak a few of my own gem file settings before I started to ensure that I was not using an native C extensions such as the mysql2 gem – JRuby cannot support those.

All the rest of the issues revolved around the fact that my application was running on a later version of Rails under JRuby, so at this point you can forget you are running on JRuby and the JVM – you are just dealing with a Rails application and there are a lot of resources out there on the net to help you.

Overall I’m very happy with the results. I am thinking of trying this out on a production environment next, and running the GlassFish or Tomcat server instead of Passenger. I also want to experiment with Rails talking to SQL Server – another Windows stalwart.

Advertisements
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

2 Responses to Running Rails 3 on JRuby in Windows

  1. Victor says:

    Are you using JRuby for developement on SQL Server?

    I am trying to do so, but I am running into trouble testing. My rake db:test:load with a jdbc adaptor fails with the message: Task not supported by ‘jdbc’

    Have you found a work around for this?

    Thank you for your help,

    ~Victor

  2. ciaranarcher says:

    Sorry, I can’t really help! We are using SQL Server, but we are not using that Rake task – we are building a Sinatra application, and we handle database changes as a separate process.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s