需要帮助将脚本引擎加载到 Karaf

Need help loading Script Engine into Karaf

有没有人幸运地将脚本引擎加载到 Karaf 中。我看过一些关于将脚本引擎加载到 OSGi 容器中的旧链接: - 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?

但是到目前为止,加载到 karaf 中时运气不佳。我有一个简单的示例项目来说明我在这里要做的事情:

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

每次我尝试加载脚本。使用以下行:

        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.");
    }

我收到 class 未找到异常:

    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

我试过嵌入包、动态导入等...如有任何建议,我们将不胜感激。

谢谢。

通过 ScriptEngineManager 加载 ScriptEngine 可能会很复杂,因为 ScriptEngineManager 使用的 ClassLoader 可能不是您想要的。

你可以尝试直接实例化Renjin:

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

如果加载 Renjin 时确实遇到错误,这也可能会为您提供更多详细信息。