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?