简体   繁体   English

如何指定确切的犀牛实现方式,而不是JDK中嵌入的实现方式?

[英]How can I specify exact rhino implementation instead of that embedded to JDK?

I use rhino script in my application. 我在应用程序中使用了犀牛脚本。 I found that on different environments it works different. 我发现在不同的环境下它的工作原理有所不同。 For example, on open-jdk this code doesn't work 例如,在open-jdk上,此代码不起作用

eval("JSON.stringify({id:1})")

whereas on Oracle's JDK works. 而在Oracle的JDK上有效。

This is obviously because each JDK contains it's own implementation of Rhino. 这显然是因为每个JDK都包含其自己的Rhino实现。

I added the following to dependencies: 我在依赖项中添加了以下内容:

<dependency>
    <groupId>org.mozilla</groupId>
    <artifactId>rhino</artifactId>
    <version>1.7R4</version>
</dependency>

How can I specify to use this implementation ? 如何指定使用此实现?

Update : I call rhino not directly but through javax.script API 更新 :我不是直接调用犀牛,而是通过javax.script API

new ScriptEngineManager().getEngineByName("JavaScript").eval("JSON.stringify({})")

You need an implementation of javax.script.ScriptEngine which uses which uses the package org.mozilla.javascript , rather than the JDK's implementation, which uses the repackaged sun.org.mozilla.javascript.internal . 你需要的实现javax.script.ScriptEngine ,它使用它使用包org.mozilla.javascript ,而不是JDK的实现,它使用重新打包sun.org.mozilla.javascript.internal

de.christophkraemer:rhino-script-engine is such an implementation, borrowed from the OpenJDK source. de.christophkraemer:rhino-script-engine是一个这样的实现,它是从OpenJDK源码中借来的。 More details here . 更多细节在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM