Manish Chakravarty (manish_chaks) wrote,

Setting up a JRuby on Rails 3 + NetBeans dev environment

Aim: to get a dev environment up and running for what would be a mixed-mode Java/JRuby project using NetBeans as the IDE.
If NetBeans is your IDE of you choice then this blog post should help you out.
I have done these steps using a macbook pro / OSX Leopard with NetBeans 6.9 - steps should be pretty much the same on other platforms.


Download JRuby from here and extract it in a directory of your choice ( I used /Users/manish/Desktop/jruby-1.5.2 for this example )

Fire up neatbeans
Go to Project - > New Ruby on Rails project.

We will now attempt to point NetBeans to the latest version of JRuby that we downloaded.

Click on the "Manage" button
New Ruby on Rails application - manage the ruby platform

In the Ruby Platform Manager, browse and point to the "jruby" binary in the "bin" folder :

We will now attempt to setup the ruby-debugger.
Download the jruby-debug-base gem from here and save it.
Install the gem locally.
Here's the command-line trace
% ./jruby -S gem install -l ~/Desktop/ruby-debug-base-
Successfully installed ruby-debug-base-
1 gem installed
Installing ri documentation for ruby-debug-base-
Couldn't find file to include: 'VERSION'
Installing RDoc documentation for ruby-debug-base-
Couldn't find file to include: 'VERSION'

Now pull in the ruby-debug-ide gem

Here's the command-line trace
% ./jruby -S gem install --ignore-dependencies -v 0.4.6 ruby-debug-ide
Successfully installed ruby-debug-ide-0.4.6
1 gem installed
Installing ri documentation for ruby-debug-ide-0.4.6...
Installing RDoc documentation for ruby-debug-ide-0.4.6...

Switching back to netbeans, give your project and name and choose the correct platform as shown below:

Choose the correct target platform

Configure the DB - I would strongly suggest using SQLite or MySQL unless your team has a good reason to use a different database. In the example I have used derby but I do not recommend it.

We now go to the installing rails page:
We have three action items - I have marked them with blue arrows

Click on the "Install Rails button" - you get the following dialog once it gets done:
Rails installation done

After this I also installed Warbler and JRuby openssl.
Hit next and let netbeans complete the project creation.

Now that we have a JRuby on Rails 3 project created on the site, lets find out how to debug this application inside of netbeans.

Firing up the debugger ( Command-F5 ) - Netbeans tells me that it's downloading the glassfish debug gem - I am not sure why this is there - but I let it go ahead nonetheless.

Turns out I was wrong - I changed the server preferences to webrick.
Right click on the project name in the left pane , select "properties" and select Webrick server from the drop down as show below:
Change netbeans server preferences to Webrick

You would also need to comment out the entry referencing the sqlite-ruby gem in the Gemfile ( Line #8 ) as show below:
Comment out the need for sqlite3-ruby in the gemfile

We now need the activerecord-jdbcsqlite3-adapter ( we commented out sqlite in the previous step )

The command line trace on my system is as follows:

% ./jruby -S gem install activerecord-jdbcsqlite3-adapter
Successfully installed jdbc-sqlite3-
Successfully installed activerecord-jdbcsqlite3-adapter-0.9.7-java
2 gems installed
Installing ri documentation for jdbc-sqlite3-
Installing ri documentation for activerecord-jdbcsqlite3-adapter-0.9.7-java...
Installing RDoc documentation for jdbc-sqlite3-
Installing RDoc documentation for activerecord-jdbcsqlite3-adapter-0.9.7-java...

Hit F6 to run your app and voila!

Safari running JRuby on Rails 3


Further reading:
1. JRuby Debugging
2. JRuby and Rails 3 ( This information in this link is a bit outdated though )
Tags: tutorial jruby
  • Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded