GroovyClassLoader是否支持使用loadClass()进行延迟编译?
答案 0 :(得分:0)
扩展GroovyClassloader并覆盖loadclass方法
@Override
public Class loadClass(String name, boolean lookupScriptFiles,
boolean preferClassOverScript) throws ClassNotFoundException,
CompilationFailedException {
// TODO Auto-generated method stub
try
{
Class<?> loadedClass = super.loadClass(name, lookupScriptFiles, preferClassOverScript);
if (loadedClass !=null) {
return loadedClass;
}
}
catch (ClassNotFoundException e)
{
System.out.println("here --------------");
}
int indx = name.lastIndexOf('.');
String substr = name;
if (indx != -1)
{
substr = name.substring(indx + 1);
}
String groovyFileName = substr + ".groovy";
String path = "C:\\" + groovyFileName;
try
{
return parseClass(new File(path).toString(), groovyFileName);
}
catch (CompilationFailedException exception)
{
throw exception;
}
}