Michael J. Lee
Michael J. Lee

Reputation: 12416

Groovy Shell in Grails includes my grails .lib/ folder

I have a grails application which is responsible for running 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")

    }

}

Upvotes: 1

Views: 365

Answers (1)

Joshua Moore
Joshua Moore

Reputation: 24776

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.

Upvotes: 3

Related Questions