Sophie

Sophie

distrib > Fedora > 17 > x86_64 > by-pkgid > cf79c2d0ed7fa2678c515072ee6f31e4 > files > 13

jasperreports-manual-4.0.2-4.fc17.noarch.rpm

<html xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://jasperreports.sourceforge.net/jasperreports">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JasperReports 4.0.2 - Ant Compile Sample</title>
<style type="text/css">
.title {
	font-family: Arial, Verdana, Helvetica, sans-serif;
	font-size: 28px;
	font-weight: normal;
}

.toc {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.name {
	font-family: Courier New, Courier, serif;
	font-size: 16px;
	font-weight: bold;
}

.label {
	font-family: Arial, Verdana, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	font-style: italic;
}

.description {
	font-family: Arial, Verdana, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: normal;
}

.value {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.element {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.attribute {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: bold;
}

.code {
	font-family: Courier New, Courier, serif;
	font-size: 12px;
	font-weight: normal;
}

.copy {
	font-decoration: none;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 8pt;
	font-style: normal;
	color: #000000;
}

.subtitle {
	font-family: inherit;
	font-size: inherit;
	font-style: inherit;
	font-weight: bold;
	text-decoration: none;
	color: inherit;
}

</style>
</head>
<body bgcolor="#FFFFFF">
<a name="top"></a>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td colspan="2" align="right"><span class="element"><a href="../../sample.reference.html">Sample Reference</a> - <a href="../../schema.reference.html">Schema Reference</a> - <a href="../../config.reference.html">Configuration Reference</a> - <a href="http://jasperreports.sourceforge.net/api/index.html">API (Javadoc)</a></span>
<br>
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1">
</td>
</tr>
<tr valign="middle">
<td nowrap="true"><span class="title">JasperReports - Ant Compile Sample (version 4.0.2)</span></td><td align="right"><img src="../../resources/jasperreports.png" border="0"></td>
</tr>
<tr>
<td colspan="2">
<hr size="1">
</td>
</tr>
</table>
<br>
<span class="description"><span class="description">Shows how multiple JRXML files can be compiled in batch mode using the ANT build tool.</span></span>
<br>
<br>
<span class="element"><a href="http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%204.0.2/jasperreports-4.0.2-project.zip/download" target="_blank">Download All Sample Source Files</a></span>
<br>
<span class="element"><a href="http://jasperforge.org/scm/viewvc.php/tags/jr-4-0-2/jasperreports/demo/samples/antcompile/?root=jasperreports" target="_blank">Browse Sample Source Files on SVN</a></span>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 20px;">
<br>
</td><td>
<br>
</td>
</tr>
<tr>
<td colspan="2"><span class="label">Main Features in This Sample</span></td>
</tr>
<tr>
<td>
<br>
</td><td><span class="element"><a href="#antcompile">Compiling Multiple Report Template Files Using the Ant Build Tool</a></span></td>
</tr>
<tr>
<td>
<br>
</td><td><span class="element"><a href="#antdecompile">Generating the JRXML Source Files for Multiple Compiled Report Template Files Using the Ant Build Tool (Decompiling)</a></span></td>
</tr>
<tr>
<td colspan="2">
<br>
</td>
</tr>
<tr>
<td colspan="2"><span class="label">Secondary Features</span></td>
</tr>
<tr>
<td></td><td><span class="element"><a href="../groovy/index.html#reportcompilers">Report Compilers</a></span></td>
</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td><img src="../../resources/px.gif" border="0" width="20" height="1"></td><td width="80%">
<br>
</td><td width="20%">
<br>
</td>
</tr>
<tr>
<td colspan="6" align="right"><a name="antcompile"></a><a href="#top" class="toc">top</a></td>
</tr>
<tr>
<td colspan="6">
<hr size="1">
</td>
</tr>
<tr valign="top">
<td><img src="../../resources/jr-16x16.png" border="0"></td><td colspan="4"><span class="name">Compiling Multiple Report Template Files Using the Ant Build Tool</span></td><td align="right"><span class="copy">Documented by 
	<a href="mailto:teodord@users.sourceforge.net" class="copy">Teodor Danciu</a></span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
<tr valign="top">
<td>
<br>
</td><td nowrap="true"><span class="label">Description / Goal</span></td><td>
<br>
</td><td colspan="3"><span class="description">
How to compile all your JRXML report source files at application build time using the Ant build tool.
    </span></td>
</tr>
<tr valign="top">
<td>
<br>
</td><td colspan="1"><span class="label">Since</span></td><td>
<br>
</td><td colspan="3"><span class="description">0.4.6</span></td>
</tr>
<tr valign="top">
<td>
<br>
</td><td nowrap="true"><span class="label">Other Samples</span></td><td>
<br>
</td><td colspan="3">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td><span class="element"><a href="../beanshell/index.html">/demo/samples/beanshell</a></span></td>
</tr>
<tr>
<td><span class="element"><a href="../groovy/index.html">/demo/samples/groovy</a></span></td>
</tr>
<tr>
<td><span class="element"><a href="../java1.5/index.html">/demo/samples/java1.5</a></span></td>
</tr>
<tr>
<td><span class="element"><a href="../javascript/index.html">/demo/samples/javascript</a></span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
<tr>
<td>
<br>
</td><td colspan="5"><span class="description">
The JRXML files represent the source files for static report templates. These report templates need to be 
prepared for use at runtime by compiling them into <span class="code"><code>*.jasper</code></span> files, which are basically serialized 
<span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JasperReport.html" target="_blank">JasperReport</a></span> objects, ready for filling with data.
<br>

<br>
Report template source files having the <span class="code"><code>*.jrxml</code></span> file extensions are compiled into serialized object files 
having the <span class="code"><code>*.jasper</code></span> file extension, just like Java source files having the <span class="code"><code>*.java</code></span> file extension 
are transformed into Java bytecode binary files with the <span class="code"><code>*.class</code></span> file extension.
<br>
The transformation of <span class="code"><code>*.jrxml</code></span> files into <span class="code"><code>*.jasper</code></span> files should be part of the application 
build process, just as the compilation of <span class="code"><code>*.java</code></span> files into <span class="code"><code>*.class</code></span> files is.
In the majority of cases, when the report templates are static and do not change at runtime (only data feed into them changes), 
there is no point in deploying source JRXML files  with the application.
<br>
After all, when deploying a Java application, you deploy <span class="code"><code>*.class</code></span> files, packaged up in JARs, not source <span class="code"><code>*.java</code></span> files. 
The same technique is applicable to JR report template files, where compiled <span class="code"><code>*.jasper</code></span> files should be created 
at application built time and then deployed as part of the application classpath as resources.
<br>

<br>
The JasperReports library provides a built-in Ant task for compiling source JRXML report template files into <span class="code"><code>*.jasper</code></span> files. 
This task is represented by the <span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/ant/JRAntCompileTask.html" target="_blank">JRAntCompilerTask</a></span> task and 
works very similar to the Ant built-in <a href="http://ant.apache.org/manual/CoreTasks/javac.html" target="_blank" class="element">Javac</a> task.
<br>

<br>
This task scans source folders and looks up for report template files (usually having the JRXML file extension) 
and compiles them into <span class="code"><code>*.jasper</code></span> files which are placed into a destination folder hierarchy.
<br>
The destination folder tree is similar to the source folder tree, meaning that the relative location of source files from 
the root source folder is preserved for the resulting <span class="code"><code>*.jasper</code></span> files.
<br>

<br>
Similar to the <span class="code"><code>Javac</code></span> task, the source folders can be specified using either the <span class="code"><code>srcdir</code></span> attribute 
of the task (when there is only one root source folder) or using a nested <span class="code"><code>&lt;src&gt;</code></span> tag (when source files 
are scattered across multiple paths).

<br>

<br>
Open the <span class="code"><code>build.xml</code></span> file in the current sample and notice how the custom Ant task called <span class="code"><code>jrc</code></span> is defined:
<br>

<br>

<pre>
&lt;taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask"&gt; 
  &lt;classpath refid="classpath"/&gt;
&lt;/taskdef&gt;

</pre>
This task definition uses a <span class="code"><code>&lt;classpath&gt;</code></span> element which contains the JasperReports JAR and all its required dependencies.
<br>

<br>
Then, the custom <span class="code"><code>jrc</code></span> task is used to compile report templates having the <span class="code"><code>*.jrxml</code></span> file extension found under 
the sample's <span class="code"><code>reports</code></span> folder. This source folder is specified using the <span class="code"><code>srcdir</code></span> attribute of the <span class="code"><code>jrc</code></span> task 
in the <span class="code"><code>compile1</code></span> target of the <span class="code"><code>build.xml</code></span> file:
<br>

<br>

<pre>
&lt;target name="compile1"&gt; 
  &lt;mkdir dir="./build/reports"/&gt; 
  &lt;jrc 
    srcdir="./reports"
    destdir="./build/reports"
    tempdir="./build/reports"
    keepjava="true"
    xmlvalidation="true"&gt;
   &lt;classpath refid="runClasspath"/&gt;
   &lt;include name="**/*.jrxml"/&gt;
  &lt;/jrc&gt;
&lt;/target&gt; 

</pre>
The <span class="code"><code>compile2</code></span> target in the same <span class="code"><code>build.xml</code></span> file performs the same report compilation process, 
but the source folder is specified using a nested <span class="code"><code>&lt;src&gt;</code></span> tag with filesets. The nested source tag allows compiling report 
templates that are scattered through many different locations and are not grouped under a single root report source folder.
<br>

<br>

<pre>
&lt;target name="compile2"&gt;
  &lt;mkdir dir="./build/reports"/&gt; 
  &lt;jrc 
    destdir="./build/reports"
    tempdir="./build/reports"
    keepjava="true"
    xmlvalidation="true"&gt;
   &lt;src&gt;
    &lt;fileset dir="./reports"&gt;
     &lt;include name="**/*.jrxml"/&gt;
    &lt;/fileset&gt;
   &lt;/src&gt;
   &lt;classpath refid="runClasspath"/&gt;
  &lt;/jrc&gt; 
&lt;/target&gt; 

</pre>
Notice that both report compilation targets have a <span class="code"><code>&lt;classpath&gt;</code></span> nested element, used to specify the classpath used by the report 
compiler. This so called run-classpath contains classes that are referenced inside the report templates themselves, such as scriptlet classes, 
chart customizers and so forth.
<br>
In this particular sample, both source JRXML files make use of such helper classes found in the <span class="code"><code>src</code></span> folder of the samples. 
These helper classes have to be compiled before the report templates are compiled, using the <span class="code"><code>javac</code></span> target of the <span class="code"><code>build.xml</code></span> file.
<br>

<br>
In addition to the <span class="code"><code>srcdir</code></span> and the <span class="code"><code>destdir</code></span> attributes, the <span class="code"><code>jrc</code></span> custom Ant task shipped with JasperReports 
supports the following attributes:
<br>

<br>

<ul>

<li>
<span class="code"><code>compiler</code></span> : Name of the class that implements the <span class="element"><a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/design/JRCompiler.html" target="_blank">JRCompiler</a></span> interface to be used for compiling the reports (optional).</li>

<li>
<span class="code"><code>xmlvalidation</code></span> : Flag to indicate whether the XML validation should be performed on the source report template files (<span class="code"><code>true</code></span> by default).</li>

<li>
<span class="code"><code>tempdir</code></span> : Location to store the temporarily generated files (the current working directory by default).</li>

<li>
<span class="code"><code>keepjava</code></span> : Flag to indicate if the temporary Java files generated on the fly should be kept and not deleted automatically (<span class="code"><code>false</code></span> by default).</li>

</ul>

<br>

<br>
In our sample, we use the default report compiler, which is the JDT-based compiler, because the JDT JAR is found in the classpath. 
This compiler works on the assumption that report expressions are Java expressions and thus it produces a Java class file dynamically containing 
all the report expressions and compiles it using the JDT Java compiler. Normally, this report compiler does all the Java class file generation 
and compilation in-memory and does not work with actual files on disk, which makes it very flexible and easy to deploy in all environments. 
However, if the <span class="code"><code>keepjava</code></span> flag is turned to <span class="code"><code>true</code></span>, it will save the report's temporary Java source file on disk, 
in the specified <span class="code"><code>tempdir</code></span>. This is useful for debugging report expressions in certain cases.
<br>

<br>
Depending on the report expression language they are mapped to, other report compiler implementations might produce script files instead of Java files, 
for report expression evaluation. The <span class="code"><code>keepjava</code></span> and the <span class="code"><code>tempdir</code></span> attributes will still work for them, except that the files 
that will be kept into the temporary location will not be Java source files but script files, also helpful for debugging.
    </span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
<tr>
<td colspan="6" align="right"><a name="antdecompile"></a><a href="#top" class="toc">top</a></td>
</tr>
<tr>
<td colspan="6">
<hr size="1">
</td>
</tr>
<tr valign="top">
<td><img src="../../resources/jr-16x16.png" border="0"></td><td colspan="4"><span class="name">Generating the JRXML Source Files for Multiple Compiled Report Template Files Using the Ant Build Tool (Decompiling)</span></td><td align="right"><span class="copy">Documented by 
	<a href="mailto:" class="copy"></a></span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
<tr valign="top">
<td>
<br>
</td><td nowrap="true"><span class="label">Description / Goal</span></td><td>
<br>
</td><td colspan="3"><span class="description">
How to re-create the JRXML source files for multiple compiled report templates using the Ant build tool. 
This is useful in cases where only the compiled <span class="code"><code>*.jasper</code></span> files of older reports are available, 
the initial <span class="code"><code>*.jrxml</code></span> source files being lost.
    </span></td>
</tr>
<tr valign="top">
<td>
<br>
</td><td colspan="1"><span class="label">Since</span></td><td>
<br>
</td><td colspan="3"><span class="description">3.7.1</span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
<tr>
<td>
<br>
</td><td colspan="5"><span class="description">
[Under Construction]
    </span></td>
</tr>
<tr>
<td colspan="6">
<br>
</td>
</tr>
</table>
<br>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td>
<hr size="1">
</td>
</tr>
<tr>
<td align="center"><span class="copy">&copy; 2001-2010 Jaspersoft Corporation <a href="http://www.jaspersoft.com" target="_blank" class="copy">www.jaspersoft.com</a></span></td>
</tr>
</table>
</body>
</html>