javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "peg" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at Test.main(Test.java:32)
Exception in thread "main" java.lang.RuntimeException: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "peg" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1
at Test.main(Test.java:37)
Caused by: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "peg" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at Test.main(Test.java:32)
Sample Code is:
public static void main(String[] args) throws Exception {
try {
InputStream pegIs = PEG.class.getResourceAsStream("/peg-0.10.0.min.js");
Reader pegReader = new InputStreamReader(pegIs);
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
Invocable invocable = (Invocable) engine;
Bindings scope = engine.createBindings();
engine.eval(pegReader,scope);
engine.eval("peg.options = function(){return {}}",scope);
scope.clear();
} catch (Exception e){
e.printStackTrace();
throw new RuntimeException(e);
}
}