Open GoogleCodeExporter opened 9 years ago
yes, i can't do it work. who can help us?
Original comment by blackbla...@126.com
on 5 Jul 2012 at 2:20
The issue here is that there is no 'print' function exposed to the javascript
interface.
You are of-course at liberty to define your own. The following worked for me...
====
Test.java:
----
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Test {
public static void main(String[] args) throws ScriptException {
ScriptEngine eng = new ScriptEngineManager().getEngineByName("jav8");
Jav8Printer jav8 = new Jav8Printer();
eng.put("jav8", jav8);
eng.eval("var print = function (arg) {jav8.print(arg);};");
eng.eval("print('Hello, world!');");
}
}
====
====
Jav8Printer.java
----
public class Jav8Printer {
public void print(Object args) {
System.out.println(args.toString());
}
}
====
What does not work however is saying:
eng.eval("var print = jav8.print;");
and I shall file a separate issue report against that.
Original comment by a.freddi...@gmail.com
on 22 Aug 2012 at 8:36
i have same issue on window, debug find that eng == null.
what can i do?
Original comment by blackbla...@126.com
on 19 Sep 2012 at 4:03
When "eng == null" this likely means the jar has not been installed as a
referenced library to your project.
Original comment by MUDC...@gmail.com
on 11 Feb 2014 at 11:51
Original issue reported on code.google.com by
gustavo....@modernizingmedicine.com
on 5 Apr 2012 at 1:55