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? Thanks for your time!
on 2012-10-13 00:27
on 2012-10-14 21:54
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'. Markus
on 2012-10-15 04:19
Yep, ERB is the "embedded ruby" templating language. Works at terminal: → irb jruby-18.104.22.168 :001 > require 'erb' => true jruby-22.214.171.124 :002 > ERB => ERB Jordan
on 2012-10-15 04:38
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: "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 there: ScriptingContainer container = new OSGiScriptingContainer(bundle, LocalContextScope.SINGLETHREAD, LocalVariableBehavior.TRANSIENT); container.setHomeDirectory("classpath:/META-INF/jruby.home"); Rhett : https://github.com/NUBIC/suite_authorization_sourc...
on 2012-10-15 08:04
In our rcp-project we get the engine from http://jruby.org/apidocs/org/jruby/embed/jsr223/JR...) Markus
on 2012-10-15 17:16
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... -Tom On Sun, Oct 14, 2012 at 9:38 PM, Rhett Sutphin <email@example.com> wrote: >> > >> > http://xircles.codehaus.org/manage_email > > -- blog: http://blog.enebo.com twitter: tom_enebo mail: firstname.lastname@example.org
on 2012-10-15 18:58
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...) 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