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, jruby.shell, 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.