David Rabinowitz
David Rabinowitz

Reputation: 30448

What are the pros and cons of using GroovyClassLoader vs. GroovyShell

I need to run some external code from my Java application that will be updated frequently and orthogonally to the rest of the application. As I do not to re-deploy the entire application for every code change (and for other reasons as well) we chose to use groovy for this code, and store it either on the file system or in the database.

From the documentation I understand I have two ways to run the code - Using the GroovyShell or the GroovyClassLoader (eval does not fit here)

What are the pros and cons of each method?

Upvotes: 1

Views: 1376

Answers (2)

djangofan
djangofan

Reputation: 29669

GroovyShell uses the default classloader until you load something in a script that customizes the classpath, then it switches to a custom GroovyClassLoader, which can cause problems loading some jdbc drivers or jndi items, etc... So, if your default classloader already has the classpath it needs and , and if you can avoid instantiating a new GroovyClassLoader object in your Java code, then loading a shell script with a simple GroovyShell will use the default classloader and you'll be better off for it.

Hope I understood your question.

Upvotes: 2

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

GroovyShell uses GroovyClassLoader underneath. Use GroovyShell unless you need a feature that's only provided by GroovyClassLoader.

Upvotes: 3

Related Questions