June 20, 2008

Installing jRuby on Mac OS X

Posted by Sudhindra Rao

I was trying to install and run jruby on my mac(Jruby 1.1.2). After downloading and unzipping the installer I tried to run jruby.
But all I was getting was an exception


Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main

Googling did not yield anything useful.
So I started debugging and I found that the CLASSPATH had not been specified correctly in the
jruby file.
All I was getting was an empty string for the CLASSPATH which is why it was not able to find the jruby.jar(which contains the org.jruby.Main class)

To fix this I added

CLASSPATH=./../lib/jruby.jar

before CLASSPATH was being used in the jruby file.

Looks like CLASSPATH has not been defined in the jruby.bat file too. So jruby won't work on Windows either.

Hope this tip helps someone.

5 comments:

Bjarni said...

Hi,

where exactly did you add the CLASSPATH?

Sudhindra Rao said...

On my machine jruby was extracted and installed under /opt/jruby1.1.2.
This directory contains a bin folder where you have the jruby(shell file). That is where you add this CLASSPATH declaration.

so I added it in /opt/jruby-1.1.2/bin/jruby file.

Hope this helps.
Thanks for reading.

Sudhindra

Bjarni said...

Ok, cool, got it up and running.

One thought though, I've been searching through the web trying to find some info on developing a rails app with jruby activerecord-jdbc for db2/as400 ON A MAC.

Any ideas?

Sudhindra Rao said...

The driver should work regardless of whether it is a mac. Try writing an example in java that talks to this driver. If that works the one with ruby code should work seamlessly. If not I think the jruby team would be able to help. I know that they are working on a lot of these things now.

Freddy Andersen said...

For me I just did port install jruby and I got jruby 1.1.3 ready to go...

freddy@new-host-2:~$ sudo port install jruby
Password:
---> Fetching jruby
---> Attempting to fetch jruby-src-1.1.3.tar.gz from http://dist.codehaus.org/jruby/
---> Verifying checksum(s) for jruby
---> Extracting jruby
---> Configuring jruby
---> Building jruby with target jar
---> Staging jruby into destroot
---> Installing jruby 1.1.3_0
---> Activating jruby 1.1.3_0
---> Cleaning jruby
freddy@new-host-2:~$ jruby -v
jruby 1.1.3 (ruby 1.8.6 patchlevel 114) (2008-11-17 rev 6586) [i386-java]
freddy@new-host-2:~$

Welcome