简体   繁体   English

如何强制Groovy脚本引擎在文件中输出已编译的类?

[英]How to force Groovy Script Engine to output compiled classes in files?

I googled and found out you can make GroovyScriptEngine output scriptCache into class files by setting setTargetDirectory. 我搜索了一下,发现可以通过设置setTargetDirectory使GroovyScriptEngine输出scriptCache成为类文件。 But when I execute the code something like below from scala, it doesn't generate class files. 但是,当我从scala执行类似下面的代码时,它不会生成类文件。

How do you set GroovyScriptEngine to output class files from scripts compiled by GroovyScriptEngine? 如何设置GroovyScriptEngine从GroovyScriptEngine编译的脚本输出类文件?

var gse = new GroovyScriptEngine()
gse.getConfig().setTargetDirectory("c:/test")
var scriptClass = gse.loadScriptByName("SomeGroovyClass.groovy")

The GroovyScriptEngine does not seem ( from looking at the source ) to use that property of CompilerConfiguration GroovyScriptEngine似乎( 从源代码 GroovyScriptEngine似乎不使用CompilerConfiguration该属性。

It would need to be passed in the constructor of the inner ScriptClassLoader , so that the GroovyClassLoader that it extends gets the configuration when it is constructed. 它需要在内部ScriptClassLoader的构造函数中ScriptClassLoader ,以便它扩展的GroovyClassLoader在构造时获得配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM