Upgrading from Java 7 to 8 can involve a lot of moving parts, and there are a number of versions of common libraries that may not work well with Java 8, but most of them can be made to work with Java 8 with a little effort. This post is about getting JasperReports 5.x to operate smoothly with Java 8.
If you search for this topic on the Internet, you may find a few related solutions, but I would like to share details on how we solved this issue. Before going into more details of the workaround or proposed solution, let’s see what the out-of-the-box run-time behavior of JasperReports 5.x is with Java 8 during report compilation.
If we observe the exception stack trace, it clearly states that it fails to compile the Jasper report template. Now, let’s talk about how this compilation process works. JasperReports API offers a façade class called, net.sf.jasperreports.engine.JasperCompileManager which has set of static methods for compiling for Jasper report templates. Documentation for this class says,
And if you look at the “default.jasperreports.properties” or any other configuration properties of JasperReports 5.x, we don’t find any specific configurations for Java compiler, therefore it uses available Java compilers in the environment. Now if we look at the dependency graph for JasperReports
You can find “eclipse:jdtcore:3.1.0” -Eclipse Incremental Java Compiler. After validating our observations against the issue reported as part of #3498-0 and proposed workarounds, we tried upgrading the version of jdtcore specified by Jasper, by over-riding the dependency in our Gradle build, and it worked.
Here is a Gradle script snippet with the fix we tried that works like a charm!
Technically, this means “exclude the version of jdtcore provided by Jasper, and replace it with the most current version of the 3.1.x series”
Or you can even use “org.eclipse.jdt.core.compiler:ecj:4.4” and follow the same approach for Maven too. Probably the difference between ecj and jdtcore is a topic for another post. Once we are done with complete migration to Java 8, we are planning to upgrade the version of JasperReports to 6.x. I look forward to subsequent posts to share a few more Java 8 migration experiences.