From e74c8275e20e3396ed9af3ba6b6c7020d00a5b38 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Sat, 11 Nov 2017 18:13:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BE=AA=E7=8E=AF=E5=88=A4=E6=96=ADext?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=AF=BB=E6=89=BEjs=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=B9=B6=E4=B8=94=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 2 +- .../yumc/YumCore/engine/MiaoScriptEngine.java | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index ac1e49b..7f79861 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 pw.yumc YumCore - 1.8.6 + 1.8.7 ${project.artifactId} diff --git a/src/main/java/pw/yumc/YumCore/engine/MiaoScriptEngine.java b/src/main/java/pw/yumc/YumCore/engine/MiaoScriptEngine.java index e96c070..06cc89e 100644 --- a/src/main/java/pw/yumc/YumCore/engine/MiaoScriptEngine.java +++ b/src/main/java/pw/yumc/YumCore/engine/MiaoScriptEngine.java @@ -18,6 +18,8 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleBindings; +import lombok.val; + /** * 喵式脚本引擎 * @@ -59,21 +61,25 @@ public class MiaoScriptEngine implements ScriptEngine, Invocable { } catch (final NullPointerException ignored) { } if (engine == null) { - File nashorn = new File(System.getProperty("java.ext.dirs").split(File.pathSeparator)[0], "nashorn.jar"); - if (nashorn.exists()) { - try { - Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); - // 设置方法的访问权限 - method.setAccessible(true); - // 获取系统类加载器 - URL url = nashorn.toURI().toURL(); - method.invoke(Thread.currentThread().getContextClassLoader(), url); - engineManager = new ScriptEngineManager(); - engine = engineManager.getEngineByName(engineType); - } catch (NoSuchMethodException | MalformedURLException | IllegalAccessException | InvocationTargetException ignored) { - ignored.printStackTrace(); + val dirs = System.getProperty("java.ext.dirs").split(File.pathSeparator); + for (String dir : dirs) { + File nashorn = new File(dir, "nashorn.jar"); + if (nashorn.exists()) { + try { + Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + // 设置方法的访问权限 + method.setAccessible(true); + // 获取系统类加载器 + URL url = nashorn.toURI().toURL(); + method.invoke(Thread.currentThread().getContextClassLoader(), url); + engineManager = new ScriptEngineManager(); + engine = engineManager.getEngineByName(engineType); + } catch (NoSuchMethodException | MalformedURLException | IllegalAccessException | InvocationTargetException | NullPointerException ignored) { + } + return; } } + throw new UnsupportedOperationException("当前环境不支持 " + engineType + " 脚本类型!"); } }