This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GroovyClassloaderTest { | |
@Test | |
public void loadGroovyScript() throws Exception { | |
CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); | |
compilerConfiguration.setClasspath("/base/directory/containing/groovy/files"); | |
GroovyClassLoader gcl = new GroovyClassLoader(getClass().getClassLoader(), compilerConfiguration); | |
Class<?> cls = gcl.loadClass("SampleClass", true, true, true); | |
} | |
} |
What this does is to create a Groovy Classloader that is configured to automatically compile all groovy files under "/base/directory/containing/groovy/files". If you then ask this Classloader for a class that exists as a normal class, it will provide it from it's parent. If however the class is actually written in an uncompiled .groovy file in that directory, it will also provide it having compiled the .groovy file automatically.
No comments:
Post a Comment