我想在java中执行一个groovy脚本,并且对java和groovy都是新手我有一些问题。只是想学习。
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import groovy.lang.GroovyShell;
import javax.naming.Binding;
import java.io.File;
public class envHealth extends GroovyShell{
public static void main(String[] args)
{
try
{
ClassLoader parent = envHealth.class.getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class groovyClass = loader.parseClass(new File("M://CheckEDWs.groovy"));
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
Object[] args1 = {};
groovyObject.invokeMethod("run",args);
System.out.println("Success");
}
catch(Exception e)
{
System.out.println("Failed");
}
}
}
失败了
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError:org / apache / commons / cli / ParseException