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

443 views Asked by At

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({})")
1

There are 1 answers

0
seanf On

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.

de.christophkraemer:rhino-script-engine is such an implementation, borrowed from the OpenJDK source. More details here.