When should I compile my report templates and how?

The exact moment when report compilation needs to occur depends on whether report design templates change during the application's execution.

In many cases, report designs (JRXMLs) do not change at runtime - the application only provides dynamic data and parameter values to predefined report templates to produce runtime reports.

In such cases, report designs can be considered application source code and it is recommended to compile them during the application build process and to include the compile reports (*.jasper files) in the binary/deployed application. Read more on how to do this in the JasperReports Tutorial section on report compilation.

In more complex scenarios, report templates need to be generated, changed or deployed at runtime, hence reports have to be compiled at runtime.

In such cases it is recommended to use the JDT-based report compiler because:

  • It doesn't need to use (temporary) files, like the JDK-based report compilers.
  • It uses the context classloader to resolve classes, while JDK-based report compiler work with a filesystem classpath that needs to be set up by the user.

To use the JDT-based report compiler, one simply has to include the JDT compiler jar distributed with JasperReports (or a JDT core jar downloaded from Eclipse).

The failure to include the JDT compiler jar in your application may result in errors like CreateProcess: javac -classpath or package net.sf.jasperreports.engine does not exist. The simplest solution to fix such errors is to leverage the JDT report compiler, thus avoiding the need of properly setting up a JDK-based report compiler.

Feedback
randomness