Java Reference
In-Depth Information
We can invoke the new target from the command line as follows:
ant viewDesign
After invoking the target, we should see a window very similar to the one we saw
when previewing the JRXML template.
Compiling a JRXML Template through ANT
JasperReports includes a custom ANT task that can be used to compile report
templates. Since we don't have to write code to perform the compilation, compiling
reports in this manner is very convenient. However, for certain applications we need
to compile a report programmatically, for example, in situations where the JRXML
file is created at run time. The custom ANT task included by JasperReports is called
JRC. It is defined in the net.sf.jasperreports.ant.JRAntCompileTask class. Let
us add a third target to our build.xml file to invoke the JRC task.
<project name="FirstReport XML Design Preview" default="viewDesignXML"
basedir=".">
<description>Previews and compiles our First Report</description>
<property name="file.name" value="FirstReport"/>
<!-- Directory where the JasperReports project file was extracted,
needs to be changed to match the local environment -->
<property name="jasper.dir"
value="/usr/local/share/java/jasperreports-1.1.0"/>
<property name="classes.dir" value="${jasper.dir}/build/classes"/>
<property name="lib.dir" value="${jasper.dir}/lib"/>
<path id="classpath">
<pathelement location="./"/>
<pathelement location="${classes.dir}"/>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="viewDesignXML"
description="Launches the design viewer to preview the XML
report design.">
<java classname="net.sf.jasperreports.view.JasperDesignViewer"
fork="true">
<arg value="-XML"/>
<arg value="-F${file.name}.jrxml"/>
<classpath refid="classpath"/>
</java>
 
Search WWH ::




Custom Search