Java Reference
In-Depth Information
Creating a Binary Report Template
JRXML files cannot be used directly to generate reports. They need to be compiled
into JasperReports' native binary format. Compiled report templates are called
Jasper
iles
. There are two ways to compile a JRXML file into a Jasper file. We can
either do it programmatically, or we can do it through a custom ANT task provided
by JasperReports.
Compiling a JRXML Template Programmatically
A JRXML template can be compiled into a Jasper file and saved to disk by
calling the
compileReportToFile()
method on the
net.sf.jasperreports.
engine.JasperCompileManager
class. There are three overloaded versions of the
JasperCompileManager.compileReportToFile()
method, listed below:
JasperCompileManager.compileReportToFile(String
sourceFileName)
.
JasperCompileManager.compileReportToFile(String
sourceFileName
,
String
destFileName)
.
JasperCompileManager.compileReportToFile(JasperDesign
jasperDesign
,
String
destFileName)
.
•
•
•
The following table illustrates the parameters used in these methods:
Parameter
Description
This contains the location of the JRXML template to
be used to generate the compiled report template. It
can be an absolute or a relative path. The generated
compiled report template is saved using the same
name and location as the supplied JRXML file,
substituting the file extension with
.jasper
.
String sourceFileName
This is used to determine the file name used to save
the compiled report template in the file system. It
can contain an absolute or a relative path.
String destFileName
This contains an in-memory representation of
the report design.
net.sf.jasperreports.
engine.design.JasperDesign
instances can
be created by calling one of the several methods
in the
net.sf.jasperreports.engine.xml.
JRXmlLoader
class.
JasperDesign jasperDesign