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

Reply via email to