This blog post guide you to solve a specific problem / exception encountered while working with Jasper Reports and Java frameworks. If this blog post helps you to solve your problem, please post your comment in the comments section. If not, please write us your problem and Jasper Reports exception with more details.
If you are working with Jasper Reports and not compiled properly with correct language settings, you would encounter the exception java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException. If you are a Java developer, you would wonder why the hell it is searching for the Groovy API org.codehaus.groovy.control.CompilationFailedException which is no where related to your Java project.
The issue is that when you create JRXML (It is the Jasper Reports template XML file that will have the actual layout of the report. This layout can be created using the iReport or Jasper Studio tools), it has an option to specify the language which will parse the XML and convert to the PDF report. This JasperReports supports the multiple languages like Java, Groovy, etc. If you are working in the Java project, you have to specify the language attribute as “Java”.
- Also Read : Closures in Groovy
Coming to the above exception (org.codehaus.groovy.control.CompilationFailedException), this would occur when you have set the language as Groovy and then trying to run in the Java web applications. The runtime would search for the Groovy API for parsing the JasperReports. By, default the language is set as Java in the drop down of the report properties. You can find the screenshot below how it appears in the JasperStudio window. The same will be absent if the value is Java (because it is default value) and any other language you can find in XML source as language=”Groovy”.
Solution : To fix the above issue, update the language as Java in the report and then compile. It will work without any issues. If you are using iReport/JasperStudio, select the root object in your Report Inspector. Then in the Properties window, select Java from the Languages drop-down. If you are editing the source code of JRXML file, remove language=”groovy” from the file altogether. The default value of Java will be considered.
Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName (JRClassLoader.java:157) at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName (JRClassLoader.java:115) at net.sf.jasperreports.engine.JasperCompileManager.getCompiler (JasperCompileManager.java:854) at net.sf.jasperreports.engine.JasperCompileManager.compile (JasperCompileManager.java:354) at net.sf.jasperreports.engine.JasperCompileManager.compileReport (JasperCompileManager.java:614) at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView. loadReport(AbstractJasperReportsView.java:511) at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView. loadReport(AbstractJasperReportsView.java:476) at org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView. initApplicationContext(AbstractJasperReportsView.java:306) at org.springframework.context.support.ApplicationObjectSupport.initApplication Context(ApplicationObjectSupport.java:119) at org.springframework.web.context.support.WebApplicationObjectSupport. initApplicationContext(WebApplicationObjectSupport.java:72) at org.springframework.context.support.ApplicationObjectSupport. setApplicationContext(ApplicationObjectSupport.java:73) at org.springframework.context.support.ApplicationContextAwareProcessor. invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117) at org.springframework.context.support.ApplicationContextAwareProcessor. postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. applyBeanPostProcessorsBeforeInitialization (AbstractAutowireCapableBeanFactory.java:396) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. initializeBean (AbstractAutowireCapableBeanFactory.java:1505) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. doCreateBean(AbstractAutowireCapableBeanFactory.java:521) ... 52 more Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.control. CompilationFailedException
I hope this blog post would help you to solve the above problem. If you are working with Jasper Reports and facing any issues, please write us in the comments section.