If you encounter the java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
error while compiling a JasperReports template, it means your project lacks the required Groovy library. Here’s how to resolve it:
1. Switch Report Language to Java
By default, JasperReports uses Groovy for expressions. If you aren’t using Groovy, switching to Java can resolve the issue.
In iReport/Jaspersoft Studio:
- Open the report in the designer.
- Select the root element (e.g.,
<jasperReport>
) in the Report Inspector. - In Properties, set Language to Java.
In the JRXML File:
Remove language="groovy"
from the <jasperReport>
tag or explicitly set it to Java:
<jasperReport ... language="java">
2. Add the Groovy Library to Your Project
If your report requires Groovy, add the necessary JAR files to your classpath.
For Maven Users
Add this dependency to your pom.xml
(adjust the version as needed):
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.10</version> <!-- Use 3.0.4 for newer projects -->
</dependency>
For Ant/Manual Builds
- Download the Groovy JAR from Groovy’s official site.
- Place the JAR (e.g.,
groovy-all-2.4.10.jar
) in your project’slib
folder or include it in Ant’s classpath.
3. Update TIBCO Jaspersoft Studio (if applicable)
If using TIBCO Jaspersoft Studio:
- Download the latest Groovy JAR.
- Replace the outdated JAR in the plugins folder:
- Navigate to:
./TIBCOJaspersoftStudio-6.3.1.final/plugins/
- Delete outdated JARs (e.g.,
groovy-all_2.4.5.jar
). - Add the new JAR (e.g.,
groovy-all-2.4.10.jar
).
- Navigate to:
4. Verify Classpath in Ant Script
Ensure your Ant build script includes the Groovy JAR:
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/> <!-- Includes Groovy JAR -->
</fileset>
</path>
Why This Happens
- JasperReports defaults to using Groovy for dynamic expressions.
- If the required Groovy JAR is missing, it triggers
NoClassDefFoundError
. - Switching to Java removes the Groovy dependency but requires ensuring that no Groovy-specific expressions exist in your template.
By following these steps, you’ll resolve the missing Groovy library issue and successfully compile your JasperReports template. 🚀