If you are having issues with bundling JasperReports, a J2EE server, and Maven, you are not alone. There are many bumps in the road for getting JasperReports integrated with Tomcat/J2EE Container and building with Maven. Hopefully, this blog entry will make things slightly easier.
Firstly, there is the confusion of where the JasperReports dependency lies in the maven2 repository. There is a very suggestive entry for: {groupid: jasperreports, artifactid: jasperreports} however, that entry only hosts versions 0.5.0 to 3.5.3. The entry: {groupid: net.sf.jasperreports, artifactid: jasperreports} contains the versions 3.6 to the latest version. In addition, the last entry contains an artifactid of jasperreports-fonts, handy if special reporting fonts are requested from your reports.
Secondly, if you are getting ClassNotFoundException or NoClassDefFoundError for the class: net/sf/jasperreports/engine/JRException your issue with still with the POM configuration for JasperReports. The ClassNotFoundException is a runtime error, so despite a successful build, you will still see this. Despite the jasperreports-x.x.x.jar file being in your web-inf folder, you may still see this error.
You must modify the scope of the component in the pom.xml. Change the scope from compile [which is needed to build], to “provided.” (http://maven.apache.org/pom.html#Dependencies) Provided not only uses the dependency to build, but update’s the container’s classpath to use this as a runtime dependency.
Continue reading “Fixing Classpath Issues with JasperReports, J2EE, and Maven”