I’m trying to enable some ruby scripting (and hopefully eventually
webapps) from within an OSGi environment.
I can see that jruby-1.6.0 includes code to support OSGi [1] but I can’t
find much documentation on it. Is there a beginner’s guide somewhere?
As a trial I’ve created a bundle with a single Component (I’m using OSGi
Declarative Services):
@Component
public class RubyHWRunner {
@Activate
public void start(ComponentContext context) {
Bundle bundle = context.getBundleContext().getBundle();
OSGiScriptingContainer container
= new OSGiScriptingContainer(bundle);
container.runScriptlet("/ruby/hello_world.rb");
}
}
where the /ruby/hello_world.rb is a trivial ruby script which I’ve
included within the bundle.
When the component is activated I get two exceptions:
(1) java.lang.ClassCastException: java.util.ArrayList cannot be cast to
[Ljava.lang.Object;
at
org.jruby.embed.osgi.utils.OSGiBundleClassLoaderHelper.internalGetFelixBundleClassLoader(OSGiBundleClassLoaderHelper.java:161)
at
org.jruby.embed.osgi.utils.OSGiBundleClassLoaderHelper.getBundleClassLoader(OSGiBundleClassLoaderHelper.java:110)
at
org.jruby.embed.osgi.internal.JRubyOSGiBundleClassLoader.addBundle(JRubyOSGiBundleClassLoader.java:103)
at
org.jruby.embed.osgi.internal.JRubyOSGiBundleClassLoader.(JRubyOSGiBundleClassLoader.java:78)
at
org.jruby.embed.osgi.OSGiScriptingContainer.(OSGiScriptingContainer.java:86)
at
org.jruby.embed.osgi.OSGiScriptingContainer.(OSGiScriptingContainer.java:73)
at
com.epimorphics.osgitest.ruby.RubyHWRunner.start(RubyHWRunner.java:25)
This one is specific to felix. If I switch to using equinox as the run
time then it goes away. Does this means that the jruby osgi isn’t
compatible with felix?
(2) java.io.IOException: Unable to find the /META-INF/jruby.home folder
in the bundle ‘org.jruby.jruby’; is the org.jruby.jruby bundle unzipped?
at
org.jruby.embed.osgi.utils.OSGiFileLocator.getFileInBundle(OSGiFileLocator.java:72)
…
This one happens whichever runtime I use.
This fits with the javadoc comment “Setup of jruby home pointing at the
jruby bundle by default. Supporting unzipped jruby bundle for now.” [2]
However, sorry for the stupid question (I’m something of newbie to OSGi)
but how can I set up a suitable “unzipped jruby bundle”?
I’m using eclipse + bndtools as my dev environment. If I put a suitably
renamed jruby.jar in my bndtools repository
(…/cnf/repo/org.jruby.jruby) I can load the jruby bundle fine but if I
unjar that jar into the same place I can’t persuade the runtime to
accept it (tested for both equinox and felix). I’ve tried setting an
explicit felix.auto.deploy.dir and putting the unjared jruby.jar in
there but to no avail.
Dave
[1] http://jira.codehaus.org/browse/JRUBY-5384
[2]
http://www.jruby.org/apidocs/org/jruby/embed/osgi/OSGiScriptingContainer.html