Groovy Shell in Grails includes my grails .lib/ folder
I have a grails application which is responsible for r开发者_开发技巧unning uploaded groovy files. My application then looks up the uploaded groovy files and then executes them using the GroovyShell.
It seems as if any .jar files included in my grails lib folder also gets added to the classpath of my GroovyShell (this is not good for me). Is there a way to get a 'clean' classpath that includes no external references?
Example:
MyGrailsApp/lib/my-java-code.jar
my-java-code.jar
contains a class called com.ClassInExternalLib
GroovyService{
def runTask(){
GroovyShell shell = new GroovyShell()
shell.evaluate("assert new com.ClassInExternalLib() != null")
}
}
Simply set the ClassLoader to an Classloader which only contains the libraries you wish to expose to the GroovyShell when you construct the GroovyShell. See the Groovy API documentation for more information.
精彩评论