How add to class path used by GroovyScriptEngine?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

How add to class path used by GroovyScriptEngine?

Marc Palmer Local


I'd like to be able to add new JARs to the classpath at startup of my  
application, similar to the WEB-INF/lib mechanism in Servlets - but  
not controlled and loaded by a servlet container.

However I'd like these Java classes to be available to Groovy scripts  
running in my application. I'm not sure how I can do this if Groovy  
is already loaded on the classpath with an already existing classloader.

Anybody got any clues?

Basically my application is a container in itself, that will allow  
you to run multiple Groovy-based applications. I would like each of  
these Groovy-based applications to be able to provide their own Java/
Groovy utility classes and Jars that Groovy scripts will be able to use.

As far as I recall this is tricky or impossible, because of Groovy  
will use the classloader that loaded the groovy JAR (which did not  
load these per-application Jars)

Does Groovy have a mechanism for specifying extra ClassLoaders to use  
when looking up classes?
Thanks in advance.
~ ~ ~
Marc Palmer ([hidden email])
AnyWare Ltd.