0
因此,我有一些代碼可以成功加載和編譯腳本。這很好。接下來,雖然,我想能夠在編譯腳本中調用一個函數。不幸的是,我看不出有什麼辦法可以編譯腳本。在Java腳本API中的腳本中調用Javascript函數
Compilable compEngine = (Compilable)engine;
compiledScripts.put(filename, compEngine.compile(new InputStreamReader(in)));
compiledScripts.get(filename).eval();
//All works until this point. The compiled script does not seem to be invokable.
Invocable inv = (Invocable) compiledScripts.get(filename);
inv.invokeFunction("onLoad");
有沒有辦法做到這一點?如果是這樣,怎麼樣?如果不是,那麼在不編譯腳本時通常會有多大的性能下降?
你在這裏使用什麼庫?犀牛? –
Rhino是Java中的默認JavaScript引擎,所以是的。 – Katherine1