I am using Java 7, and I have the following code that uses the jsondiffpatch Javascript library:
logger.debug("CURRENT PATH=" + Paths.get("").toAbsolutePath());
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
reader = new FileReader("webclient/common/js/jsondiffpatch.min.js");
engine.eval(reader);
If you look at line 48 of jsondiffpatch.js (the uncompressed version of jsondiffpatch.min.js
), you can see it references another module:
var packageInfoModuleName = '../package.json';
When executing the Java code, the engine.eval(reader)
line can't find package.json
and throws the following exception:
javax.script.ScriptException: Error: Cannot find module '../package.json' in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224) ~[na:1.7.0_51]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) ~[na:1.7.0_51]
at nms.server.domain.AuditManager$ConfigAuditProcessor.run(AuditManager.java:465) ~[nms.jar:na]
Caused by: sun.org.mozilla.javascript.internal.JavaScriptException: Error: Cannot find module '../package.json' (<Unknown source>#1)
at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Interpreter.java:1066) ~[na:1.7.0_51]
at sun.org.mozilla.javascript.internal.Interpreter.interpret(Interpreter.java:849) ~[na:1.7.0_51]
at sun.org.mozilla.javascript.internal.InterpretedFunction.call(InterpretedFunction.java:162) ~[na:1.7.0_51]
at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(ContextFactory.java:430) ~[na:1.7.0_51]
at com.sun.script.javascript.RhinoScriptEngine$1.superDoTopCall(RhinoScriptEngine.java:116) ~[na:1.7.0_51]
at com.sun.script.javascript.RhinoScriptEngine$1.doTopCall(RhinoScriptEngine.java:109) ~[na:1.7.0_51]
at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(ScriptRuntime.java:3160) ~[na:1.7.0_51]
at sun.org.mozilla.javascript.internal.InterpretedFunction.exec(InterpretedFunction.java:173) ~[na:1.7.0_51]
at sun.org.mozilla.javascript.internal.Context.evaluateReader(Context.java:1169) ~[na:1.7.0_51]
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:214) ~[na:1.7.0_51]
The jsondiffpatch.min.js
file is located in the webclient/common/js
directory, and the package.json
file is located in the webclient/common
directory.
The logger.debug
line printed out the following for the current working directory:
CURRENT PATH=/usr/local/project/version/Software
So I tried copying the package.json
file to the /usr/local/project/version
directory, and I still got the same exception.
Why can't the ScriptEngine find the package.json
file?