Dojo not loading in rhino laid in java

I am trying to display a dojo diagram server server. I came across Rhino and envjs to emulate a server side browser. when I tried the sample program to load dojo.js in the rhino built into java impl, an exception is thrown,

An exception was thrown in the main thread javax.script.ScriptException: sun.org.mozilla.javascript.EcmaError: ReferenceError: "location" is not defined. (No. 15) in line No. 15.

My code is as follows:

import javax.script.*; import java.io.*; public class Java6RhinoRunner { public static void main(String[] args) throws ScriptException { new Java6RhinoRunner().load(args[0]); } private final ScriptEngine engine; public Java6RhinoRunner() throws ScriptException { ScriptEngineManager factory = new ScriptEngineManager(); this.engine = factory.getEngineByName("JavaScript"); this.engine.put("Java6RhinoRunner", this); this.engine.eval("function load(filename) { Java6RhinoRunner.load(filename); }"); } public void load(String filename) throws ScriptException { try { this.engine.eval(new FileReader(filename)); } catch(FileNotFoundException e) { throw new RuntimeException("Error loading javascript file: " + filename, e); } } } 

A lot of googling was done, but all in vain. Please help me solve this problem.

+1
source share
1 answer

The code crashes due to the Dojo method detects that it is running in the Rhino environment.

Dojo code was written for compatibility with the Rhino shell ( org.mozilla.javascript.tools.shell.Main ) and detects Rhino by looking for functions defined by org.mozilla.javascript.tools.shell.Global . If they are missing, Dojo assumes that it is running in a browser environment.

Perhaps you can emulate these functions by defining them in your script engine, but I have not tried it.

I wrote a blog post when I started Dojo in the built-in Rhino , but it does not use the ScriptEngine API.

+1
source

Source: https://habr.com/ru/post/980548/


All Articles