<script>:1:in `require': no such file to load -- test/unit (LoadError)
from <script>:1
...internal jruby stack elided...
from Kernel.require(<script>:1)
from (unknown).(unknown)(:1)
<script>:1:in `require': no such file to load -- test/unit (LoadError)
from <script>:1
javax.script.ScriptException: java.lang.RuntimeException: org.jruby.exceptions.RaiseException: no such file to load -- test/unit
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:116)
at internal.Activator$EngineFactoryTracker.addingService(Activator.java:36)
at org.osgi.util.tracker.ServiceTracker$Tracked.trackAdding(ServiceTracker.java:1064)
at org.osgi.util.tracker.ServiceTracker$Tracked.track(ServiceTracker.java:1042)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:967)
at org.eclipse.osgi.framework.internal.core.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:91)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:1248)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:211)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:141)
at org.eclipse.osgi.framework.internal.core.Framework.publishServiceEventPrivileged(Framework.java:1563)
at org.eclipse.osgi.framework.internal.core.Framework.publishServiceEvent(Framework.java:1538)
at org.eclipse.osgi.framework.internal.core.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:122)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.createServiceRegistration(BundleContextImpl.java:666)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:617)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:685)
at org.ops4j.pax.script.internal.ExtenderActivator$1.addingEntries(ExtenderActivator.java:103)
at org.ops4j.pax.swissbox.extender.BundleWatcher.register(BundleWatcher.java:186)
at org.ops4j.pax.swissbox.extender.BundleWatcher.onStart(BundleWatcher.java:145)
at org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle$Stopped.start(AbstractLifecycle.java:121)
at org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle.start(AbstractLifecycle.java:49)
at org.ops4j.pax.script.internal.ExtenderActivator.start(ExtenderActivator.java:128)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:1009)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1003)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:984)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:355)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1074)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:616)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:508)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:299)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:489)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:211)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:321)
Caused by: java.lang.RuntimeException: org.jruby.exceptions.RaiseException: no such file to load -- test/unit
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:116)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:113)
... 33 more
Caused by: org.jruby.exceptions.RaiseException: no such file to load -- test/unit
at (unknown).new(<script>:1)
at Kernel.require(<script>:1)
at (unknown).(unknown)(:1)
I did some debugging and I think, that the ThreadContextClassLoader is (this time) not the problem. In fact JRuby isn't finding jrubyHome, as the warning message pointed out:
Warning: JRuby home "/1/META-INF/jruby.home" does not exist, using /tmpThe jrubyHome variable is set during the initialization of the JRubyEngineFactory in SystemPropertyCatcher inspecting the jar file if the system property or environment variable is not set. The problem is, that looking for a classpath resource in an OSGi environment returns an OSGi-specific URL (bundleresource://1/META-INF/jruby.home in Equinox for example). The URL scheme is then stripped of (resource.toURI().getSchemeSpecificPart()), leading to the path showed above that cannot be found from the JRuby point of view.
I could use an equinox specific resolver to resolve the OSGi bundleresource myself and setting a file-URI as the jruby.home system property, but this only works if I do this before the JRubyEngineFactory gets initialized. In OSGi the JRubyEngineFactory will be automatically registered as a service (so called extender pattern), but this happens before my application code gets a chance to set jruby.home.
Any ideas how to solve this?