-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (45 loc) · 1.75 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
function require(classes, callback) {
try {
var Class = java.lang.Class;
var e = java.lang.ClassNotFoundException;
var engine = javax.script.ScriptEngine;
var scriptManager = javax.script.ScriptEngineManager;
var bindings = javax.script.SimpleBindings;
var ScriptContext = javax.script.ScriptContext;
var JSObject = Java.type("jdk.nashorn.api.scripting.JSObject");
var fnc = Java.type("jdk.nashorn.api.scripting.JSObject");
var System = java.lang.System;
bindings = new javax.script.SimpleBindings();
var cls = "";
var clsName = "";
for (var i = 0; i < classes.length; i++) {
cls = classes[i];
clsName = cls.substring(cls.lastIndexOf(".") + 1, cls.length);
System.out.println("Class: " + cls + " Name: " + clsName);
Class.forName(cls);
bindings.put(clsName, Java.type(cls));
}
scriptManager = new javax.script.ScriptEngineManager();
engine = scriptManager.getEngineByName("nashorn");
// bindings.put("System", java.lang.System);
engine.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
scriptManager.setBindings(bindings);
if (callback !== null) {
fnc = engine.eval(callback);
fnc.call();
}
} catch (e) {
//my class isn't there!
e.printStackTrace();
}
}
require(["javax.script.ScriptEngine",
"java.util.ArrayList",
"java.lang.System"], function () {
System.out.println(new Date().toString());
});