Search code examples
javaweb-applicationsgroovyclassloader

Groovy cast exception occurring in deployed web application after script modification


I asked a similar question previously, but wanted some clarification on the mechanics of the GroovyScriptEngine and how class loading is performed. I have a Vaadin web application that contains groovy classes in WEB-INF. The webapp loads UI logic via a GroovyScriptEngine. Here is a sequence of events that leads to an error:

  1. Deploy war to tomcat & start server, application runs as expected
  2. I make an insignificant change to groovy file located in the exploded WEB-INF folder (for instance, a remark)
  3. Refresh page, GSE apparently reloads classes, and application bombs with GroovyCastException: Cannot cast object 'com.company.myclass@7cde31f8' with class 'com.company.myclass' to class 'com.company.myclass'.

I understand that this may be a class loader issue. Suggestions? I thought the whole point of the GroovyScriptEngine was that it handled hot-edited groovy classes without having to restart the container.


Solution

  • For sure this is ClassLoader issue. If you need to reload classes (I suppose for faster development), try JRebel. Works well with groovy and tomcat.