Resolving issues with RJB and RVM caused by Snow Leopard Java update

We have a client product that we’ve built using the Ruby Java Bridge (RJB) gem. Generally, it works great both on our servers and on our local development machines (we use Macs here in the Labs). That was until recently, when the code that utilizes RJB started throwing “Can’t Create Java VM” errors for me locally.

After talking it over with the team, we discovered that the recent Java software update from Apple appeared to have precipitated the problem. My teammate, Peter, was able to fix things on his machine by installing the latest version of RJB. That didn’t work for me, though, and the difference turned out to be that Peter was developing with the system Ruby on his computer while I was using Ruby Version Manager (RVM) to develop against different Rubies as needed. When I installed recent versions of RJB, I got “[BUG] cross-thread violation on rb_gc()” errors.

I did some digging, and it seems that the latest version of RJB makes a lot of assumptions and only compiles itself against the system Ruby, basically ignoring RVM Rubies. I thought I was stuck. Luckily for me, just as I was throwing up my hands and adding “rvm use system” to my .bash_profile, another clever teammate, Tom, figured out the necessary steps to get things working again. We thought we would share them here in case anyone else was searching for a solution to this problem:

  1. Download the Java JDK 1.5 for Leopard (it’s available from various resources on the Internet, including itUploads) – java.1.5.0-leopard.tar.gz
  2. Unzip the package:
    tar -zxvf java.1.5.0-leopard.tar.gz
  3. Move the unzipped package to your Java versions directory:
    sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/
  4. I’m not entirely sure if it matters, but you should probably make sure that folder ends up belonging to root:
    sudo chown -R root:wheel /System/Library/Frameworks/JavaVM.framework/
  5. Update the 1.5.0 symlinks in your Versions folder:
    cd /System/Library/Frameworks/JavaVM.framework/Versions/
    sudo rm 1.5.0 && sudo ln -s 1.5.0_leopard 1.5.0
  6. Add or update your JAVA_HOME environment variable in .bashrc or .bash_profile (etc) to read:
    export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/
  7. Install an older version of RJB for any RVM gemsets that need it (I chose 1.2.0 because we had seen it work with RVM previously, but I’ve seen other people recommend 1.2.5):
    rvm use 1.8.7@project
    gem install rjb -v 1.2.0

It’s a very specific solution to a very specific problem, but hopefully it helps somebody out there.

Interested in working with experts like this at Foraker Labs? We'd love to talk about what you have in mind. Contact us today for more information.