groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Groovy and Serialization
Date Wed, 16 Nov 2016 15:43:31 GMT


On 16.11.2016 16:27, Venkat Sadasivam wrote:
> Hello:
>
> We are using Groovy in the web application and some classes loaded via
> Groovy script get serialized and added into HttpSession object. In
> clustered environment when other Tomcat server try to deserialize we get
> ClassNotFoundException.
>
> I tried something like below code in a simple Java.
>
> ScriptEngineManager factory = new ScriptEngineManager(Serialization.class.getClassLoader());
>
> ScriptEngine engine = factory.getEngineByName("Groovy");
>
> String groovyScript = IOUtils.toString(Serialization.class.getResourceAsStream("/blah.groovy"),
Charset.defaultCharset());
>
> Class<?> myClass = (Class<?>) engine.eval(groovyScript); // this line loads
org.venkat.Blah class
>
> GroovyObject myObj = (GroovyObject) myClass.newInstance();
>
> Serialization.class.getClassLoader().loadClass("org.venkat.Blah"); // this like shows
class not found exception

> Is there any way to load Groovy script classes into parent classloader?

you do not need a parent, you need the right child. Children of 
ClassLaoders are always supposed to ask their parents first, before 
serving a loadClass call themselves.

So I assume that:
myClass.getClassLoader().laodClass("org.venkat.Blah")
would work.

Is that right?


bye Jochen

Mime
View raw message