119 Labs LLC

Ideas on Technology

Reasonable JRuby Env With IDEA

I’m all for using TextMate (or hopefully soon Ultraedit for osx) for straight rails dev. I’m starting on a project that uses both clojure and rails so I wanted something that would play nicer for cross-language development. My favorite IDE from the Java side of things is by far IntelliJ IDEA. They have a relatively new version out with ruby support so I thought I’d give it a go setting up a jruby based rails project. It ended up being a little more complicated than just download and install so here you go: First head over to the jetbrain’s website and download a demo copy of IDEA 9. Make sure to get the ultimate edition since ruby dev is disabled in their community edition. After that snag the most recent version of jruby which as of this writing was 1.4.0. In order to follow along exactly you’ll want the straight bin version, but with a little modification to paths any version should do. I keep all of my (non-maven) java libraries in /Library/JavaDev just swap that out for whatever directory you use. Place the downloaded jruby-bin in /Library/JavaDev/

cd /Library/JavaDev/ curl http://jruby.kenai.com/downloads/1.4.0/jruby-bin-1.4.0.tar.gz > jruby-bin-1.4.0.tar.gz tar xzvf jruby-bin-1.4.0.tar.gz

make sure your user has permissions to execute files in the bin directory. As a matter of good house keeping, I also like to setup a symlink

ln -s jruby-1.4.0 jruby

next lets see where ruby is currently running from type

which gem

It most likely is running under /usr/bin/gem. We want to change that temporarily so we can update the gem system. Lets change our path and update the gem system

export JRUBY_HOME=/Library/JavaDev/jruby export PATH=$JRUBY_HOME/bin:$PATH which gem

the last command should now read /Library/JavaDev/jruby/bin/gem. If at any point you now close your terminal window you’ll need to run the last three commands again to make sure you’re working with the right gem base. Time to update the gems on your system: gem install rails gem update system gem install activerecord-jdbcsqlite3-adapter gem install jdbc-sqlite3 gem install activerecord-jdbcmysql-adapter You will probably see a message “JRuby limited openssl loaded. gem install jruby-openssl for full support.” As long as this is just a development station don’t worry about it. Now on to IDEA. Open the dmg and copy IDEA to your application folder. Run the app and create a new Ruby project. Once you get to the point that you need a project SDK click configure and add. The file IDEA is looking for is $JRUBY_HOME/bin/jruby. It will detect the lib folders from there. Last step make sure you’re using the appropriate sql adapter in your database.yml file. For sqlite your dev should look something like:

development: adapter: jdbcsqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000

Notice the adapter is jdbcsqlite3 rather than the standard sqlite3 That’s it. If you want to use a db other than sqllite, you’ll need to install the appropriate gem. IDEA will warn you & let you fix it if you forget to do this so no big deal. For reference:
  • OSX 10.6.2
  • Jruby 1.4.0
  • Rails 2.3.5
  • Idea Ultimate 9.0.1