Friday, June 22, 2012

Ran into a rather nasty Grails 2.0.4 bug the other day...

After deploying my first real production Grails 2.x application, which uses 2 plugins I also wrote, I got the lovely error trying to start the war file in Tomcat 6:


SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Lgrails/test/mixin/services/ServiceUnitTestMixin; at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NoClassDefFoundError: Lgrails/test/mixin/services/ServiceUnitTestMixin; at java.lang.Class.privateGetDeclaredFields(Class.java:2308) at java.lang.Class.getDeclaredField(Class.java:1897) ... 1 more Caused by: java.lang.ClassNotFoundException: grails.test.mixin.services.ServiceUnitTestMixin ... 3 more There is some magic combination of plugins I think is causing this. It originates from one of my plugins, but I can't find anything wrong with it, other than Grails did not package the class (It shouldn't be looking for it AFAIK). So here is my workaround solution, which is working for now (Add to BuildConfig.groovy): grails.war.resources = { stagingDir, args -> // Manually copy the grails-plugin-testing-2.0.4.jar into war due to bug in Grails 2.0.4 // For some reason grails is making the war depend on this jar from the grails distro copy(file: "lib/grails-plugin-testing-2.0.4.jar", tofile: "${stagingDir}/WEB-INF/lib/grails-plugin-testing-2.0.4.jar") } You can find this in your Grails 2.x distro, under the dist folder. I currently can't re-create it from a scratch project, it happens when I add more complex things to the mix like a maven dependency to another grails plugin coming from my artifactory server.

No comments: