简体   繁体   中英

Using javax.script or Rhino to run javascript in Java with browser context (e.g. envjs)?

I am trying to run Protovis javascript from a Java program using javax.script :

ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval(new java.io.FileReader("protovis-d3.1.js"));

In order to run this, the JavaScript engine needs to have all the context of a web browser. The best option for this seems to be envjs . Unfortunately it seems that the version of Rhino included in the JVM isn't up to date and doesn't include everything that's necessary for envjs.

Has anyone had any success working with a browser context from javax.script, or am I missing something?

This is related to this question: "Can I create a 'window' object for javascript running in the Java6 Rhino Script Engine" .

You might want to look at http://jrex.mozdev.org/

It seems that you want to embed the full browser functionality within the JVM.

Also check http://ejohn.org/blog/bringing-the-browser-to-the-server/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM