I use JRuby under OSGi several places.  I also have to do step #1.

In my user story, the non-workingness of step #2 is a good thing; the OSGi
paradigm is helping restrict my REPL to see only what I mean it to -- users
can't accidentally/on-purpose go in and randomly exercise Java classes at
will, although they can use Ruby to exercise objects I've exposed
intentionally.  So ... "correcting" it so that require 'java' works
transparently under OSGi might actually cause a security issue for me,
unless it was done carefully.  I think the behavior I'd ideally want would
be for the interpreter to use the OSGi finder associated with the bundle
*where I instantiate the JRuby Runtime* but I have no good idea how to do
this without introducing an OSGi dependency in JRuby.

One way to do it is to create an OSGi JRuby bundle that wraps the actual
JRuby JAR, but then overlays it with some local classes that provide the
needed OSGi-specific knowledge.  It's simple, relatively maintainable, and
works fine, but I wish there was a better and cleaner way to inject the
desired classloader enhancements.

On Mon, Nov 29, 2010 at 9:07 PM, Anthony Juckel <ajuc...@gmail.com> wrote:

> 1) I had to use ScriptingContainer#setClassLoader(ClassLoader) to make sure
> that my bundle's classloader was used to lookup classes within JRuby.  My
> bundle then does a Require-Bundle on org.jruby.jruby.
> 2) After that was done, in order for require 'java' to work, I had to
> update the jruby.bnd.template to export builtin.* so my application bundle
> could see the builtin resources.  I'm not a big fan of this second step, so
> either I'm doing something wrong in my sample app, or a more intelligent
> classloading change would have to be made within JRuby itself.
>

Reply via email to