Is the Rhino () download function available in JavaScript provided by javax.script?

Some JavaScript files that were developed for the Rhino shell use load () to load additional JavaScript files. I am trying to inject functions from one of these Rhino JavaScript files using javax.script. Unfortunately, the load () function is not implemented by javax.script JavaScript. When I try to eval () a script containing load (), the following error occurs:

com.sun.script.javascript.RhinoScriptEngine:-1:in `eval': javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "load" is not defined. 

Does javax.script provide the load () function when evaluating a JavaScript file from a Java program (not from a shell)?

+7
javascript load rhino javax.script
source share
1 answer

The download function is very old. In the latest RC (RC3) Rhino, the commonJS module program exists .

You will have to switch to the built-in version of Rhino. By creating a script context, you can set the required function.

So, if you downloaded the file './math.js' , it will become var math = require('math'); . After creating the module provider with the module URI.

+1
source share

All Articles