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
eval("JSON.stringify({id:1})")
whereas on Oracle's JDK works.
This is obviously because each JDK contains it's own implementation of 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
new ScriptEngineManager().getEngineByName("JavaScript").eval("JSON.stringify({})")
You need an implementation of
javax.script.ScriptEngine
which uses which uses the packageorg.mozilla.javascript
, rather than the JDK's implementation, which uses the repackagedsun.org.mozilla.javascript.internal
.de.christophkraemer:rhino-script-engine is such an implementation, borrowed from the OpenJDK source. More details here.