在Java8平台上执行带importPackage(...);语句的脚本时会报错下面提供方法解决报错的问题
scripting/AbstractScriptManager.java
找到第73行
engine = sem.getEngineByName("javascript");
if (c != null) {
c.setScriptEngine(path, engine);
}
in = new FileInputStream(scriptFile);
BufferedReader bf = new BufferedReader(new InputStreamReader(in,"utf-8"));
01. engine.eval(bf);
} else if (c != null && npc) {
改成
01. String lines = "load('nashorn:mozilla_compat.js');" + bf.lines().collect(Collectors.joining(System.lineSeparator()));
02. engine.eval(lines);
scripting/PortalScriptManager.java
找到第74行
final ScriptEngine portal = sef.getScriptEngine();
try {
in = new FileInputStream(scriptFile);
BufferedReader bf = new BufferedReader(new InputStreamReader(in, "utf-8"));
01. CompiledScript compiled = ((Compilable) portal).compile(bf);
compiled.eval();
} catch (final FileNotFoundException | UnsupportedEncodingException | ScriptException e) {
System.err.println("讀取傳送點腳本出錯: " + scriptName + ":" + e);
FileoutputUtil.log(FileoutputUtil.ScriptEx_Log, "讀取傳送點腳本出錯 (" + scriptName + ") " + e);
改成
01. String lines = "load('nashorn:mozilla_compat.js');" + bf.lines().collect(Collectors.joining(System.lineSeparator()));
02. CompiledScript compiled = ((Compilable) portal).compile(lines);
完成, 然後編譯運作看看吧!
本文来源于心动冒险岛(www.lnshengyou.com),如需转载[用java8配置环境的方法],请写明出处
上一篇:关于服务端编写NPC的一些个人浅解