有人有幸将脚本引擎加载到 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.");
}
我得到一个类未找到异常:
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
我尝试过嵌入 bundle 、动态导入等...任何建议将不胜感激。
谢谢。
最佳答案
通过 ScriptEngineManager 加载 ScriptEngine 可能会很复杂,因为 ScriptEngineManager 使用的 ClassLoader 可能不是您想要的。
您可以尝试直接实例化Renjin:
RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
RenjinScriptEngine engine = factory.getScriptEngine();
如果加载 Renjin 时确实遇到错误,这也可能为您提供更多详细信息。
关于java - 需要帮助将脚本引擎加载到 Karaf 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40708234/