Gotcha: Embedding JRuby

15 11 2006

Here’s something I learned about embedding JRuby:

If your script requires ‘rubygems’, you need to need to make sure you set a few system properties: jruby.base, jruby.home, jruby.lib,, and jruby.script. You can look in jruby.bat to see how these can be set from the command line. If, for some reason, you can’t set them on the command line, you’ll need to set them programmatically, or else you’ll receive a NullPointerException when RbConfigLibrary loads.

Also, make sure you get the load path set properly. Running jirb and calling $:.inspect should give you a good idea what paths need to be included. All of those paths can be set the same way you’d set a Java classpath. However, one reference to *lib/ruby/1.8* has to remain relative. This is because some files (*digest/sha2*, for example) are loaded from the jruby.jar. If you are running unit tests from Ant, you may have problems because Ant tends to expand pathelements. Fortunately, it’s easy enough to append lib/ruby/1.8 to the load path before calling require ‘rubygems’ in your scripts.

This can also be found over on the JRuby wiki.




2 responses

18 11 2006
Charles Oliver Nutter

I’m really hoping we can eliminate the dependency on those system properties, or at least do a good solid guess when they’re not available. Requiring all those to be set not only sucks, it’s also incompatible with wanting to deploy multiple runtime in the same JVM. Bad, bad, bad.

If you have any ideas about how to avoid using them, please let us know. It’s on the list of things to fix/improve.

And thanks for updating the wiki! 🙂

18 11 2006

My pleasure.

I’ll give it some thought. In a week or two, I’m hoping to have a postmortum on my experiences with embedding JRuby in a JBoss server.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: