Java - 何时使用 JSR223 脚本执行基于 java 的语言
Java - When to execute java based languages using JSR223 script
Java 作为脚本语言可以同时使用 Beanshell 和 Groovy 来编写 JSR223 脚本(带有次要的 restrictions/changes)
Java 基于(模板引擎)的项目作为
Velocity 支持 JSR223
Velocity can be integrated into the Java Scripting Language Framework (as defined by the JSR-223 API).
Freemarker 在其 contributors page
中建议它
- javax.script (JSR-223) support
但是什么时候通过脚本执行基于 java 的代码更好?什么时候比作为常规 java 代码执行更好?
我发现了一个安全用法,您可以在其中使用 limited access/sandbox using ScriptEngineManager(java.lang.ClassLoader)
执行脚本
问:
I don't want any script to have access to any of my classes.
甲:
There is a constructor for ScriptEngineManager that takes a classloader. The classloader is used to load the scripting engine implementation. As classes inherit their classloaders, the scripting engine and any objects it creates should also use that classloader.
That classloader needs to deny the existence of any classes that are not white-listed.
Java 作为脚本语言可以同时使用 Beanshell 和 Groovy 来编写 JSR223 脚本(带有次要的 restrictions/changes)
Java 基于(模板引擎)的项目作为 Velocity 支持 JSR223
Velocity can be integrated into the Java Scripting Language Framework (as defined by the JSR-223 API).
Freemarker 在其 contributors page
中建议它
- javax.script (JSR-223) support
但是什么时候通过脚本执行基于 java 的代码更好?什么时候比作为常规 java 代码执行更好?
我发现了一个安全用法,您可以在其中使用 limited access/sandbox using ScriptEngineManager(java.lang.ClassLoader)
执行脚本问:
I don't want any script to have access to any of my classes.
甲:
There is a constructor for ScriptEngineManager that takes a classloader. The classloader is used to load the scripting engine implementation. As classes inherit their classloaders, the scripting engine and any objects it creates should also use that classloader.
That classloader needs to deny the existence of any classes that are not white-listed.