[英]groovy file call in java
i want to do groovy file call in java 我想在Java中进行Groovy文件调用
my source: 我的来源:
ex.groovy ex.groovy
def swingBuilder = new SwingBuilder()
swingBuilder.edt {
frame(title: 'ex', size: [200, 150], show: true) {
borderLayout(vgap: 5)
panel(constraints: BorderLayout.CENTER, border: emptyBorder(10)) {
button "a"
button "b"
}
}
}
ex1.java ex1.java
class ex1{
public static void main(String[] args)throws Exception {
File sourceFile = new File("mypath/ex.groovy");
ClassLoader clo = jview.class.getClassLoader();
GroovyClassLoader classLoader = new GroovyClassLoader(clo);
Class groovy = classLoader.parseClass(sourceFile);
GroovyObject groovyob = (GroovyObject)groovy.newInstance();
groovyob.invokeMethod("run", null);
}
}
how do i? 我如何?
help please.. 请帮助..
You could use GroovyShell (if required with Binding) 您可以使用GroovyShell(如果Binding需要)
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
public class ex1 {
public static void main(String[] args) {
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
shell.evaluate("mypath/ex.groovy");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.