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:
[".",
“/var/folders/th/fw0t5921739f9pwr0nlgcqwc0000gn/T/lib/ruby/site_ruby”,
“/var/folders/th/fw0t5921739f9pwr0nlgcqwc0000gn/T/lib/ruby/shared”,
“/var/folders/th/fw0t5921739f9pwr0nlgcqwc0000gn/T/lib/ruby/1.9”]
When I run similar code outside of OSGi, I get back paths like:
“file:/Users/jnraine/.m2/repository/org/jruby/jruby-complete/1.7.0.RC2/jruby-complete-1.7.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby”
Is there something else I need to do while setting up the scripting
container?
When I run similar code outside of OSGi, I get back paths like:
“file:/Users/jnraine/.m2/repository/org/jruby/jruby-complete/1.7.0.RC2/jruby-complete-1.7.0.RC2.jar!/META-INF/jruby.home/lib/ruby/site_ruby”
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:
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…
Rhett,
I tried your example at it began working. Many thanks!
My load path is now much more sane:
[“app/cq-quickstart-5.5.0-standalone.jar”,
“classpath:/META-INF/jruby.home/lib/ruby/site_ruby”,
“classpath:/META-INF/jruby.home/lib/ruby/shared”,
“classpath:/META-INF/jruby.home/lib/ruby/1.9”]
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()
(https://github.com/jruby/jruby/blob/master/src/org/jruby/embed/osgi/utils/OSGiFileLocator.java#L53-57)
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
Equinox.
–
Jordan Raine
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.