0

Has anyone had any luck loading script engines into Karaf. I've seen some old links regarding loading script engines into OSGi containers: - https://devnotesblog.wordpress.com/2011/09/07/scripting-using-jsr-223-in-an-osgi-environment/ - Is OSGi fundamentally incompatible with JSR-223 Scripting Language Discovery?

But have had no luck thus far loading into karaf. I have simple example project of what I'm trying to do here:

https://gitlab.com/mkwyche/helpful-hints/tree/master/renjin-karaf

Each time I try to load the script. Using the following line:

        ScriptEngineManager manager = new ScriptEngineManager();

    // create a Renjin engine:
    engine = manager.getEngineByName("Renjin");
    // check if the engine has loaded correctly:
    if(engine == null) {
        throw new RuntimeException("Renjin Script Engine not found on the classpath.");
    }

I get a class not found exception:

    at java.lang.Thread.run(Thread.java:745)[:1.8.0_60]

Caused by: java.lang.RuntimeException: Renjin Script Engine not found on the classpath. at datadidit.helpful.hints.renjin.karaf.RenjinKarafTest.testRuntime(RenjinKarafTest.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_60] at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299)[12:org.apache.aries.blueprint.core:1.6.2] at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:980)[12:org.apache.aries.blueprint.core:1.6.2] at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:736)[12:org.apache.aries.blueprint.core:1.6.2] ... 40 more

I've tried embedding bundles, dynamic-imports, etc... Any suggestions would be greatly appreciated.

Thanks.

Community
  • 1
  • 1
mkwyche
  • 183
  • 2
  • 6

1 Answers1

1

Loading a ScriptEngine via the ScriptEngineManager can be complicated because the ClassLoader used by ScriptEngineManager may not be the one you want.

You can try instantiating Renjin directly:

RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
RenjinScriptEngine engine = factory.getScriptEngine();

This might also give you more details if there is actually an error encountered when loading Renjin.

akbertram
  • 1,330
  • 10
  • 16
  • Thanks this lead me down the right direction. Got this to work in karaf with 0.7.159 will try the latest 0.8.X branch later. The solution is here: https://gitlab.com/mkwyche/helpful-hints/tree/master/renjin-karaf – mkwyche Nov 22 '16 at 02:23
  • Great! The page you linked to doesn't seem to exist- can you share so that i can add it to our project setup documentation? – akbertram Dec 05 '16 at 08:22
  • Here's the link moving things over to github: https://github.com/datadidit/helpful-hints/tree/master/renjin-karaf . Will be updating the docs on that readme this week. – mkwyche Dec 06 '16 at 13:04