-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunJS.java
More file actions
24 lines (22 loc) · 805 Bytes
/
Copy pathRunJS.java
File metadata and controls
24 lines (22 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import javax.script.*;
import java.io.*;
public class RunJS {
public static class IO {
public void print(String message) {
System.out.print(message);
}
public void println(String message) {
System.out.println(message);
}
}
public static void main(String[] args) throws ScriptException, IOException {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.put("io", new IO());
engine.eval(
"println = function(message) { io.println(message); };" +
"print = function(message) { io.print (message); };"
);
engine.eval(new InputStreamReader(new FileInputStream("script.js"), "UTF-8"));
}
}