开发者

Groovy Shell in Grails includes my grails .lib/ folder

开发者 https://www.devze.com 2023-04-04 20:38 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号