http://www.groovy-lang.org/integrating.html上的 GroovyScriptEngine 演示 不适用于我的开发环境:</p>
- 理念 2021.1.3
- JDK 1.8.0_231
- groovy-all 3.0.8
您可以在 1.4-GroovyScriptEngine 部分中查看它。
这是我的代码:
- ScriptEngineDemo.groovy
package com.rexus.common.script.integrate.engine
def binding = new Binding()
def path = getClass().getClassLoader().getResource("")
def engine = new GroovyScriptEngine([path.toURI().toURL()] as URL[])
while (true){
def greeter = engine.run('ReloadingTest.groovy',binding)
println greeter.sayHello()
Thread.sleep(1000)
}
- 重载Test.groovy
package com.rexus.common.script.integrate.engine
class Greeter {
String sayHello() {
def greet = new Dependency().message
greet
}
}
new Greeter()
- 依赖.grrovy
package com.rexus.common.script.integrate.engine
class Dependency {
String message = 'Hello, dependency 1'
}
dependency 1
当我修改为dependency 2
groovy 程序仍在运行并打印Hello, dependency 1时,cmd 输出不会改变。
这很奇怪,因为我确实遵循了官方指南,并且无法找出为什么脚本依赖项在我修改后没有重新加载。
任何想法,将不胜感激。