The class implementing ScriptEngine is loaded by reflection after being found 
in the classpath at
META-INF/services/javax.script.ScriptEngineFactory
Groovy jars have this declaration in this file:
org.codehaus.groovy.jsr223.GroovyScriptEngineFactory

I believe the bundle which creates the ScriptEngine will have to use dynamic 
import:
DynamicImport-Package: org.codehaus.groovy.jsr223
It can, then, load the class above.But you also need java.util.ServiceLoader to 
work, as the script engine uses that.
See this: http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html
The best solution, though, is to not use ScriptEngine and expose the script 
engines as OSGi services... if you can.
Hope that helps.
Renato
> Date: Tue, 13 Oct 2015 08:44:22 -0700
> From: jelra...@gmail.com
> To: users@felix.apache.org
> Subject: Re: Unable to reach Groovy script Engine from an other OSGI bundle
> 
> MyOSGIBundleSample.zip
> <http://apache-felix.18485.x6.nabble.com/file/n5015150/MyOSGIBundleSample.zip>
>   
> 
> Here is an updated version of my bundle project. I added the Felix
> OSGiScriptEngineManager to deal with what i suspect to be a class loading
> issue ( not sure though) but i am still facing a
> java.lang.ClassNotFoundException  exception as follows :
> 
> g! start 47
> Starting bundle MyBundle
>  findFactoryCandidates number found: 23
> org.apache.felix.framework
> org.apache.felix.bundlerepository
> org.apache.felix.gogo.command
> org.apache.felix.gogo.runtime
> org.apache.felix.gogo.shell
> org.apache.felix.eventadmin
> org.apache.felix.configadmin
> org.apache.felix.http.jetty
> org.apache.felix.http.servlet-api
> org.apache.felix.http.api
> org.apache.felix.webconsole
> org.osgi.service.obr
> org.apache.felix.scr
> null
> null
> org.apache.felix.scr.compat
> null
> null
> org.apache.felix.webconsole.plugins.scriptconsole
> groovy-all
>  u path: /META-INF/services/javax.script.ScriptEngineFactory
>  line org.codehaus.groovy.jsr223.GroovyScriptEngineFactory
> org.jruby.jruby
>  u path: /META-INF/services/javax.script.ScriptEngineFactory
>  line org.jruby.embed.jsr223.JRubyEngineFactory
> null
> myBundle
> java.lang.RuntimeException: java.lang.ClassNotFoundException:
> org.codehaus.groovy.jsr223.GroovyScriptEngineFactory not found by
> myBundleSample [47]
>         at
> com.king.osgi.samples.myBundle.OSGiScriptEngineManager.findManagers(OSGiScriptEngineManager.java:214)
>         at
> com.king.osgi.samples.myBundle.OSGiScriptEngineManager.<init>(OSGiScriptEngineManager.java:81)
>         at com.king.osgi.samples.myBundle.Activator.start(Activator.java:31)
>         at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
>         at org.apache.felix.framework.Felix.activateBundle(Felix.java:2220)
>         at org.apache.felix.framework.Felix.startBundle(Felix.java:2138)
>         at org.apache.felix.framework.Felix.updateBundle(Felix.java:2478)
>         at org.apache.felix.framework.BundleImpl.update(BundleImpl.java:995)
>         at org.apache.felix.framework.BundleImpl.update(BundleImpl.java:982)
>         at org.apache.felix.gogo.command.Basic.update(Basic.java:849)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at
> org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
>         at
> org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
>         at
> org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
>         at
> org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
>         at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
>         at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
>         at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
>         at
> org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
>         at org.apache.felix.gogo.shell.Console.run(Console.java:62)
>         at org.apache.felix.gogo.shell.Shell.console(Shell.java:203)
>         at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:128)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at
> org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:137)
>         at
> org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
>         at
> org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)
>         at
> org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
>         at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
>         at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)
>         at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)
>         at
> org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
>         at org.apache.felix.gogo.shell.Activator.run(Activator.java:75)
>         at java.lang.Thread.run(Unknown Source)
> *Caused by: java.lang.ClassNotFoundException:
> org.codehaus.groovy.jsr223.GroovyScriptEngineFactory not found by
> myBundleSample [47]
>         at
> org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1558)
>         at
> org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
>         at
> org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1998)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Unknown Source)
>         at
> com.king.osgi.samples.myBundle.OSGiScriptEngineManager.findManagers(OSGiScriptEngineManager.java:202)
>         ... 38 more*
> 
> 
> My bundle is sill unable to find the groovy script engine although its
> bundle is installed as i mentioned above.
> 
> 
> FYI: i am using apache felix framework 5.2.0 and i installed the
> groovy-all-2.1.6.jar ( also tested the groovy-all-2.4.4.jar)
> 
> Regards,
> 
> King
> 
> 
> 
> 
> --
> View this message in context: 
> http://apache-felix.18485.x6.nabble.com/Unable-to-reach-Groovy-script-Engine-from-an-other-OSGI-bundle-tp5015137p5015150.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
> For additional commands, e-mail: users-h...@felix.apache.org
> 
                                          

Reply via email to