The following code fragment demonstrates the use of the JasperCompileManager.
public class FirstReportCompile
public static void main(String args)
catch (JRException e)
After compiling and executing the code, we should see a file called FirstReport.
jasper in the file system. This file is the compiled template in JasperReports'
native format. For this example, we chose to use the first version of the
JasperCompileManager.compileReportToFile() method we discussed, since by
default the root file name is used for the compiled report, and we did not have an
in-memory representation of the JRXML template. If we had wished to use a
different root file name for the compiled report template, we should have used the
second version of the JasperCompileManager.compileReportToFile() method
and specified the desired file name as the second parameter.
Previewing the Compiled Report Template
The net.sf.jasperreports.view.JasperDesignViewer discussed previously can
be used to preview compiled report templates as well as JRXML templates. Again the
easiest way to execute this utility is to wrap a call to it into an ANT target. Let us add
a second ANT target to our build.xml file. We will call this new target viewDesign ,
as it will let us preview the compiled report.