Dojo没有被加载到java中的犀牛 [英] Dojo not getting loaded into rhino emmbedded in java

查看:175
本文介绍了Dojo没有被加载到java中的犀牛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试渲染dojo图表服务器端。我遇到了Rhino和envjs,用于服务器端浏览器仿真。当我尝试一个示例程序来加载嵌入在java impl中的rhino的dojo.js时,抛出异常,

I'm trying to render the dojo charts server side. I came across the Rhino and envjs for server side browser emulation. when I tried to an example program to load the dojo.js in the rhino embedded in the java impl, the exception is thrown,



线程main中的异常javax.script.ScriptException:sun.org.mozilla.javascript.EcmaError:ReferenceError:location未定义。 (#15)在第15行。

Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.EcmaError: ReferenceError: "location" is not defined. (#15) in at line number 15.


我的代码如下:

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);
    }
  }
}

已经完成了很多谷歌搜索但都是徒劳的。
请帮我解决这个问题

Lots of googling has been done but all in vain. Please help me to solve this problem

推荐答案

代码失败是因为Dojo检测到它正在运行Rhino环境。

The code fails because of the way Dojo detects that it is running in the Rhino environment.

Dojo代码是为了兼容Rhino的shell而编写的( org.mozilla.javascript.tools.shell.Main )并通过查找由 org.mozilla.javascript.tools.shell.Global 定义的特征来检测Rhino。如果这些不存在,Dojo认为它在浏览器环境中运行。

The Dojo code was written for compatibility with Rhino's shell (org.mozilla.javascript.tools.shell.Main) and detects Rhino by looking for features defined by org.mozilla.javascript.tools.shell.Global. If these are not present Dojo assumes it is running in a browser environment.

可能通过在脚本引擎中定义这些功能来模拟这些功能,但是我没有尝试了。

It is probably possible to emulate these features by defining them in your script engine but I haven't tried it.

我写了在嵌入式Rhino中运行Dojo的博客,但它不使用 ScriptEngine API。 em>

I wrote a blog post on running Dojo in embedded Rhino but it doesn't use the ScriptEngine API.

这篇关于Dojo没有被加载到java中的犀牛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆