Loading Remote Groovy Script
I'm loading a Groovy script/class from a remote server, creating a new instance, and invoking a method, as shown below:
String[] scriptUrls = { "http://10.74.192.186/groovy/Test.groovy" };
GroovyScriptEngine gse = new GroovyScriptEngine(scriptUrls);
Class groovyClass = gse.loadScriptByName("Test.groovy");
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
Object[] callArgs = {};
System.out.println(groovyObject.invokeMethod("getTest", callArgs));
How is the Groovy file compiled to bytecode when pulled off a server like this? Do I only need a JRE to run this?
I'm just a little confused how this works internally.
For ref开发者_高级运维erence, here is the Groovy file:
class Test {
String test = "test"
}
Thanks.
The Groovy file is compiled with the Groovy compiler, no JDK is needed (Groovy compiles directly to bytecode).
精彩评论