0

graal 可以在创建上下文时对 js、ruby 和其他语言进行沙箱处理,但是如何对动态加载的 jar 进行沙箱处理?例如,在 flink 中作为 udf 使用时如何对自定义上传的 jar 进行沙箱处理。

4

1 回答 1

1

Java 字节码目前无法使用 polygot API [1] 进行沙盒化。与任何其他 JDK 一样,您可以通过创建新的类加载器 [2] 来沙箱化 jar。

URLClassLoader child = new URLClassLoader(myJar.toURL(), 
this.getClass().getClassLoader());
Class classToLoad = Class.forName("com.MyClass", true, child);
Method method = classToLoad.getDeclaredMethod("myMethod");
Object instance = classToLoad.newInstance();
Object result = method.invoke(instance);

[1] http://www.graalvm.org/docs/graalvm-as-a-platform/embed/

[2]我应该如何在运行时动态加载 Jars?

于 2018-07-12T16:33:50.050 回答