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

RSS

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/
    1.5.0_leopard
  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/
    Versions/1.5.0_leopard
  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/
    1.5.0/Home
  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.

Jake Sutton

Jake Sutton Senior Software Developer When he’s not getting tattoos, riding his Triumph, playing with sharp objects, or discussing Mid-Century Modern furniture design with his dog, Mingus, Jake enjoys building awesome web apps in Ruby on Rails and fiddling around with relational databases.

Comments (10)

  1. 1
    Reply

    Scott Penberthy

    on March 10, 2011 said:

    Jake, thanks for the post. It was just what the doctor ordered this morning. I was using the Stanford Parser, which relies on RJB. The code was failing for me on Ruby 1.9.2…. until I found this post.

    Keep up the good work. Nice moustache, too.

  2. Jake Sutton
    2
    Reply

    Jake Sutton

    on March 10, 2011 said:

    Scott, glad the post was helpful for you!

    As for the ‘stache, it was only a temporary condition (though immortalized here on the site). ;)

  3. 3
    Reply

    Jay McGaffigan

    on June 6, 2011 said:

    wow. Talk about yack shaving, if I read your post correctly the problem is with rjb and not necessarily java, yet back revving java on the sun os and using an older version of rjb happens to solve the problem?

    I have openjdk on my mac and the “can’t start JVM” error happens.

  4. 4
    Reply

    Jay McGaffigan

    on June 6, 2011 said:

    and I meant to say Mac OS not sun :P

  5. 5
    Reply

    kevin Wells

    on June 8, 2011 said:

    So from what i looks like rjb has a bug that looks for libjvm_compat.dylib for mac installs, which is the correct file name for OSX JVM 1.4.1 through 1.5.*. In JVM 1.6 (the default on OSX 10.6) the library name changed to libverify.dylib. All i did was create a sym link to my install of rjb, now have to file a bug.
    sudo ln -s /System/Library/Frameworks/JavaVM.framework/Libraries/libverify.dylib /System/Library/Frameworks/JavaVM.framework/Libraries/libjvm_compat.dylib

    • Rafer Hazen
      5.1

      Rafer Hazen

      on June 28, 2011 said:

      That worked like a charm Kevin! Thanks.

  6. 6
    Reply

    Marcos Sainz

    on June 18, 2011 said:

    Thank you so much for this post. The one liner in step 7 above made my day.

  7. Jake Sutton
    7
    Reply

    Jake Sutton

    on June 20, 2011 said:

    Kevin: That’s interesting. Seems like a much easier fix, too.

    Marcos: Glad it helped!

  8. 8
    Reply

    Mark Robinson

    on July 6, 2011 said:

    FYI in case anybody else is still having trouble with this and finds this via Google.

    Usually adding the following will do the trick on OSX Snow Leopard, rvm and 1.9.2 without major rework.

    gem uninstall rjb
    gem install rjb –platform ruby

    and it will avoid using the pre-compiled Darwin version that is choking.

    Credit below to …
    https://gist.github.com/651443

    • Jake Sutton
      8.1

      Jake Sutton

      on July 6, 2011 said:

      Nice tip, Mark. Thanks!

Leave a Comment

All fields are required unless marked as optional.

Some HTML is okay.