本文介绍了ScriptEngineManager 和 ScriptEngine 无法在 Karaf OSGi 中加载(未找到 Nashorn)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ScriptEngineManagerScriptEngine 用 Ja​​va 执行一些 JavaScript 代码.我使用 Java 8 我在 Karaf OSGi 下执行此代码.

我使用的示例在示例 Java 类中运行良好,但将其打包成一个包会给我这个错误 ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider jdk.nashorn.api.scripting.未找到 NashornScriptEngineFactory

当我查看包的标头时,我看到包导入了 javax.script, 被调用类的包,但似乎 (nashorn) 没有找到提供者.

谢谢

解决方案

转到文件 etc/config.properties(位于 Karaf 安装内部),找到配置属性 org.osgi.framework.bootdelegation 并将 jdk.nashorn.* 添加到其中.完整的配置会是这样:

org.osgi.framework.bootdelegation=org.apache.karaf.jaas.boot,org.apache.karaf.jaas.boot.principal,sun.*,com.sun.*,javax.transaction,javax.transaction.*,javax.xml.crypto,javax.xml.crypto.*,org.apache.xerces.jaxp.datatype,org.apache.xerces.stax,org.apache.xerces.parsers,org.apache.xerces.jaxp,org.apache.xerces.jaxp.validation,org.apache.xerces.dom,sun.*,jdk.nashorn.*

错误已报告给 Karaf 社区.

编辑:如果您在测试中使用 Pax Exam Container 4.x for Karaf 那么不要忘记添加 org.ops4j.pax.exam.CoreOptions.bootDelegationPackage("jdk.nashorn.*") 到您的测试容器的配置.

I am trying to use ScriptEngineManager and ScriptEngine to execute some JavaScript code with Java. I use Java 8 I am executing this code under Karaf OSGi.

The example I used works fine in a sample Java Class, but packing it in a bundle gives me this error ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider jdk.nashorn.api.scripting.NashornScriptEngineFactory not found

When I look to the headers of the bundle, I see that the bundle imports javax.script, the package of the called classes but it seems that (nashorn) the provider is not found.

Thanks

解决方案

Go to file etc/config.properties (located inside of Karaf installation), find configuration property org.osgi.framework.bootdelegation and add jdk.nashorn.* to it. Complete configuration will be like this:

org.osgi.framework.bootdelegation=org.apache.karaf.jaas.boot,org.apache.karaf.jaas.boot.principal,sun.*,com.sun.*,javax.transaction,javax.transaction.*,javax.xml.crypto,javax.xml.crypto.*,org.apache.xerces.jaxp.datatype,org.apache.xerces.stax,org.apache.xerces.parsers,org.apache.xerces.jaxp,org.apache.xerces.jaxp.validation,org.apache.xerces.dom,sun.*,jdk.nashorn.*

Bug is reported to Karaf community.

Edit: If you use Pax Exam Container 4.x for Karaf in your tests then don't forget to add org.ops4j.pax.exam.CoreOptions.bootDelegationPackage("jdk.nashorn.*") to the configuration of your test container.

这篇关于ScriptEngineManager 和 ScriptEngine 无法在 Karaf OSGi 中加载(未找到 Nashorn)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 17:37