Problems running JRuby scriplets in Felix OSGi

Hi all,
I’m having trouble running JRuby scriplets inside a Felix OSGi
container. In particular, I can’t require stdlibs. I believe my load
path is improperly setup.

ScriptingContainer jruby = new
OSGiScriptingContainer(FrameworkUtil.getBundle(Renderer.class)); #
Renderer.class is where this snippet is located
jruby.runScriptlet(“puts ‘foo’”) # this works fine
jruby.runScriptlet(“require ‘erb’”) # this raises LoadError no such file
to load – erb

When a inspect $:, I get something I wouldn’t expect:

When I run similar code outside of OSGi, I get back paths like:

Is there something else I need to do while setting up the scripting

Thanks for your time!

Are you sure that erb is the right module?
If you want the interactive ruby console you have to require ‘irb’.

To test the library you can also try require ‘java’ or require ‘jruby’.


Yep, ERB is the “embedded ruby” templating language.

Works at terminal:
→ irb
jruby- :001 > require ‘erb’
=> true
jruby- :002 > ERB

=> ERB


Hi Jordan,

On Oct 12, 2012, at 5:26 PM, Jordan Raine wrote:

When I run similar code outside of OSGi, I get back paths like:

Is there something else I need to do while setting up the scripting container?

Those paths are based on the container’s JRuby home. Is it possible
there’s something that’s setting that incorrectly? It can be set from
the jruby.home system property, the JRUBY_HOME environment variable, or
with #setHomeDirectory on the ScriptingContainer.

“/var/folders/th/fw0t5921739f9pwr0nlgcqwc0000gn/T” looks like an OS X
temporary directory for whatever that’s worth.

I’ve had trouble running a Java app that embeds JRuby from an
environment where I have JRUBY_HOME set. The problem there is that the
embedded container uses the environment’s JRuby instead of the embedded
JRuby and so can’t find gems, etc. It is different from your situation,
but might point you in a direction to consider. This is how I’ve solved
the problem there1:

    ScriptingContainer container = new 



In our rcp-project we get the engine from


Are you sure you are not pulling in jruby.jar instead of
jruby-complete.jar? That could explain not getting a classpath-based
home. It would not explain why it is a random tmp-based one
though…I think warbler/rack might do something like this for
supporting exploded war file deployment…stabs in the dark…


On Sun, Oct 14, 2012 at 9:38 PM, Rhett S. [email protected]

blog: twitter: tom_enebo
mail: [email protected]

I tried your example at it began working. Many thanks!

My load path is now much more sane:

I’m still not sure exactly why the JRuby home needs to be set manually
in my env but the OSGiFileLocator class seems to be doing unexpected
things. Digging in further, OSGiFileLocator.getJRubyHomeFolder()
returns “/META-INF/jruby.home”, which I suppose is the root of the
problem. Is there an OSGi guru who can shed light on which file URL is
the correct? Perhaps it depends on the OSGi container? I am using Felix,
but I believe this OSGi code was originally developed for use with

Jordan Raine