PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 1ms

/projects/jasperreports-3.7.4/dist/docs/sample.reference/antcompile/index.html

https://gitlab.com/essere.lab.public/qualitas.class-corpus
HTML | 414 lines | 379 code | 35 blank | 0 comment | 0 complexity | d4412d808ffc117d9d641be67bde5b84 MD5 | raw file
  1. <html xmlns:jr="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  2. <head>
  3. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <title>JasperReports 3.7.4 - Ant Compile Sample</title>
  5. <style type="text/css">
  6. .title {
  7. font-family: Arial, Verdana, Helvetica, sans-serif;
  8. font-size: 28px;
  9. font-weight: normal;
  10. }
  11. .toc {
  12. font-family: Courier New, Courier, serif;
  13. font-size: 12px;
  14. font-weight: normal;
  15. }
  16. .name {
  17. font-family: Courier New, Courier, serif;
  18. font-size: 16px;
  19. font-weight: bold;
  20. }
  21. .label {
  22. font-family: Arial, Verdana, Helvetica, sans-serif;
  23. font-size: 12px;
  24. font-weight: bold;
  25. font-style: italic;
  26. }
  27. .description {
  28. font-family: Arial, Verdana, Helvetica, sans-serif;
  29. font-size: 12px;
  30. font-weight: normal;
  31. }
  32. .value {
  33. font-family: Courier New, Courier, serif;
  34. font-size: 12px;
  35. font-weight: normal;
  36. }
  37. .element {
  38. font-family: Courier New, Courier, serif;
  39. font-size: 12px;
  40. font-weight: normal;
  41. }
  42. .attribute {
  43. font-family: Courier New, Courier, serif;
  44. font-size: 12px;
  45. font-weight: bold;
  46. }
  47. .code {
  48. font-family: Courier New, Courier, serif;
  49. font-size: 12px;
  50. font-weight: normal;
  51. }
  52. </style>
  53. </head>
  54. <body bgcolor="#FFFFFF">
  55. <a name="top"></a>
  56. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  57. <tr>
  58. <td align="right" colspan="2"><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>
  59. <br>
  60. </td>
  61. </tr>
  62. <tr>
  63. <td colspan="2">
  64. <hr size="1">
  65. </td>
  66. </tr>
  67. <tr valign="middle">
  68. <td nowrap="true"><span class="title">JasperReports - Ant Compile Sample (version 3.7.4)</span></td><td align="right"><img border="0" src="../../resources/jasperreports.png"></td>
  69. </tr>
  70. <tr>
  71. <td colspan="2">
  72. <hr size="1">
  73. </td>
  74. </tr>
  75. </table>
  76. <br>
  77. <span class="description"><span class="description">Shows how multiple JRXML files can be compiled in batch mode using the ANT build tool.</span></span>
  78. <br>
  79. <br>
  80. <span class="element"><a href="http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%203.7.4/jasperreports-3.7.4-project.zip/download" target="_blank">Download All Sample Source Files</a></span>
  81. <br>
  82. <span class="element"><a href="http://jasperforge.org/scm/viewvc.php/tags/jr-3-7-4/jasperreports/demo/samples/antcompile/?root=jasperreports" target="_blank">Browse Sample Source Files on SVN</a></span>
  83. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  84. <tr>
  85. <td style="width: 20px;">
  86. <br>
  87. </td><td>
  88. <br>
  89. </td>
  90. </tr>
  91. <tr>
  92. <td colspan="2"><span class="label">Main Features in This Sample</span></td>
  93. </tr>
  94. <tr>
  95. <td>
  96. <br>
  97. </td><td><span class="element"><a href="#antcompile">Compiling Multiple Report Template Files Using the Ant Build Tool</a></span></td>
  98. </tr>
  99. <tr>
  100. <td>
  101. <br>
  102. </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>
  103. </tr>
  104. <tr>
  105. <td colspan="2">
  106. <br>
  107. </td>
  108. </tr>
  109. <tr>
  110. <td colspan="2"><span class="label">Secondary Features</span></td>
  111. </tr>
  112. <tr>
  113. <td></td><td><span class="element"><a href="../groovy/index.html#reportcompilers">Report Compilers</a></span></td>
  114. </tr>
  115. </table>
  116. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  117. <tr>
  118. <td><img height="1" width="20" border="0" src="../../resources/px.gif"></td><td><img height="1" width="20" border="0" src="../../resources/px.gif"></td><td><img height="1" width="20" border="0" src="../../resources/px.gif"></td><td><img height="1" width="20" border="0" src="../../resources/px.gif"></td><td width="100%">
  119. <br>
  120. </td>
  121. </tr>
  122. <tr>
  123. <td align="right" colspan="5"><a name="antcompile"></a><a class="toc" href="#top">top</a></td>
  124. </tr>
  125. <tr>
  126. <td colspan="5">
  127. <hr size="1">
  128. </td>
  129. </tr>
  130. <tr valign="top">
  131. <td><img border="0" src="../../resources/jr-16x16.png"></td><td colspan="4"><span class="name">Compiling Multiple Report Template Files Using the Ant Build Tool</span></td>
  132. </tr>
  133. <tr>
  134. <td colspan="5">
  135. <br>
  136. </td>
  137. </tr>
  138. <tr valign="top">
  139. <td>
  140. <br>
  141. </td><td nowrap="true"><span class="label">Description / Goal</span></td><td>
  142. <br>
  143. </td><td colspan="2"><span class="description">
  144. How to compile all your JRXML report source files at application build time using the Ant build tool.
  145. </span></td>
  146. </tr>
  147. <tr valign="top">
  148. <td>
  149. <br>
  150. </td><td colspan="1"><span class="label">Since</span></td><td>
  151. <br>
  152. </td><td colspan="2"><span class="description">0.4.6</span></td>
  153. </tr>
  154. <tr valign="top">
  155. <td>
  156. <br>
  157. </td><td nowrap="true" colspan="1"><span class="label">Other Samples</span></td><td>
  158. <br>
  159. </td><td colspan="2">
  160. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  161. <tr>
  162. <td><span class="element"><a href="../beanshell/index.html">/demo/samples/beanshell</a></span></td>
  163. </tr>
  164. <tr>
  165. <td><span class="element"><a href="../groovy/index.html">/demo/samples/groovy</a></span></td>
  166. </tr>
  167. <tr>
  168. <td><span class="element"><a href="../java1.5/index.html">/demo/samples/java1.5</a></span></td>
  169. </tr>
  170. <tr>
  171. <td><span class="element"><a href="../javascript/index.html">/demo/samples/javascript</a></span></td>
  172. </tr>
  173. </table>
  174. </td>
  175. </tr>
  176. <tr>
  177. <td colspan="5">
  178. <br>
  179. </td>
  180. </tr>
  181. <tr>
  182. <td>
  183. <br>
  184. </td><td colspan="4"><span class="description">
  185. The JRXML files represent the source files for static report templates. These report templates need to be
  186. prepared for use at runtime by compiling them into <code>*.jasper</code> files, which are basically serialized
  187. <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.
  188. <br>
  189. <br>
  190. Report template source files having the <code>*.jrxml</code> file extensions are compiled into serialized object files
  191. having the <code>*.jasper</code> file extension, just like Java source files having the <code>*.java</code> file extension
  192. are transformed into Java bytecode binary files with the <code>*.class</code> file extension.
  193. <br>
  194. The transformation of <code>*.jrxml</code> files into <code>*.jasper</code> files should be part of the application
  195. build process, just as the compilation of <code>*.java</code> files into <code>*.class</code> files is.
  196. In the majority of cases, when the report templates are static and do not change at runtime (only data feed into them changes),
  197. there is no point in deploying source JRXML files with the application.
  198. <br>
  199. After all, when deploying a Java application, you deploy <code>*.class</code> files, packaged up in JARs, not source <code>*.java</code> files.
  200. The same technique is applicable to JR report template files, where compiled <code>*.jasper</code> files should be created
  201. at application built time and then deployed as part of the application classpath as resources.
  202. <br>
  203. <br>
  204. The JasperReports library provides a built-in Ant task for compiling source JRXML report template files into <code>*.jasper</code> files.
  205. 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
  206. works very similar to the Ant built-in <a href="http://ant.apache.org/manual/CoreTasks/javac.html" target="_blank"><span class="element">Javac</span></a> task.
  207. <br>
  208. <br>
  209. This task scans source folders and looks up for report template files (usually having the JRXML file extension)
  210. and compiles them into <code>*.jasper</code> files which are placed into a destination folder hierarchy.
  211. <br>
  212. The destination folder tree is similar to the source folder tree, meaning that the relative location of source files from
  213. the root source folder is preserved for the resulting <code>*.jasper</code> files.
  214. <br>
  215. <br>
  216. Similar to the <code>Javac</code> task, the source folders can be specified using either the <code>srcdir</code> attribute
  217. of the task (when there is only one root source folder) or using a nested <code>&lt;src&gt;</code> tag (when source files
  218. are scattered across multiple paths).
  219. <br>
  220. <br>
  221. Open the <code>build.xml</code> file in the current sample and notice how the custom Ant task called <code>jrc</code> is defined:
  222. <br>
  223. <br>
  224. <pre>
  225. &lt;taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask"&gt;
  226. &lt;classpath refid="classpath"/&gt;
  227. &lt;/taskdef&gt;
  228. </pre>
  229. This task definition uses a <code>&lt;classpath&gt;</code> element which contains the JasperReports JAR and all its required dependencies.
  230. <br>
  231. <br>
  232. Then, the custom <code>jrc</code> task is used to compile report templates having the <code>*.jrxml</code> file extension found under
  233. the sample's <code>reports</code> folder. This source folder is specified using the <code>srcdir</code> attribute of the <code>jrc</code> task
  234. in the <code>compile1</code> target of the <code>build.xml</code> file:
  235. <br>
  236. <br>
  237. <pre>
  238. &lt;target name="compile1"&gt;
  239. &lt;mkdir dir="./build/reports"/&gt;
  240. &lt;jrc
  241. srcdir="./reports"
  242. destdir="./build/reports"
  243. tempdir="./build/reports"
  244. keepjava="true"
  245. xmlvalidation="true"&gt;
  246. &lt;classpath refid="runClasspath"/&gt;
  247. &lt;include name="**/*.jrxml"/&gt;
  248. &lt;/jrc&gt;
  249. &lt;/target&gt;
  250. </pre>
  251. The <code>compile2</code> target in the same <code>build.xml</code> file performs the same report compilation process,
  252. but the source folder is specified using a nested <code>&lt;src&gt;</code> tag with filesets. The nested source tag allows compiling report
  253. templates that are scattered through many different locations and are not grouped under a single root report source folder.
  254. <br>
  255. <br>
  256. <pre>
  257. &lt;target name="compile2"&gt;
  258. &lt;mkdir dir="./build/reports"/&gt;
  259. &lt;jrc
  260. destdir="./build/reports"
  261. tempdir="./build/reports"
  262. keepjava="true"
  263. xmlvalidation="true"&gt;
  264. &lt;src&gt;
  265. &lt;fileset dir="./reports"&gt;
  266. &lt;include name="**/*.jrxml"/&gt;
  267. &lt;/fileset&gt;
  268. &lt;/src&gt;
  269. &lt;classpath refid="runClasspath"/&gt;
  270. &lt;/jrc&gt;
  271. &lt;/target&gt;
  272. </pre>
  273. Notice that both report compilation targets have a <code>&lt;classpath&gt;</code> nested element, used to specify the classpath used by the report
  274. compiler. This so called run-classpath contains classes that are referenced inside the report templates themselves, such as scriptlet classes,
  275. chart customizers and so forth.
  276. <br>
  277. In this particular sample, both source JRXML files make use of such helper classes found in the <code>src</code> folder of the samples.
  278. These helper classes have to be compiled before the report templates are compiled, using the <code>javac</code> target of the <code>build.xml</code> file.
  279. <br>
  280. <br>
  281. In addition to the <code>srcdir</code> and the <code>destdir</code> attributes, the <code>jrc</code> custom Ant task shipped with JasperReports
  282. supports the following attributes:
  283. <br>
  284. <br>
  285. <ul>
  286. <li>
  287. <code>compiler</code> : 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>
  288. <li>
  289. <code>xmlvalidation</code> : Flag to indicate whether the XML validation should be performed on the source report template files (<code>true</code> by default).</li>
  290. <li>
  291. <code>tempdir</code> : Location to store the temporarily generated files (the current working directory by default).</li>
  292. <li>
  293. <code>keepjava</code> : Flag to indicate if the temporary Java files generated on the fly should be kept and not deleted automatically (<code>false</code> by default).</li>
  294. </ul>
  295. <br>
  296. <br>
  297. In our sample, we use the default report compiler, which is the JDT-based compiler, because the JDT JAR is found in the classpath.
  298. This compiler works on the assumption that report expressions are Java expressions and thus it produces a Java class file dynamically containing
  299. all the report expressions and compiles it using the JDT Java compiler. Normally, this report compiler does all the Java class file generation
  300. 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.
  301. However, if the <code>keepjava</code> flag is turned to <code>true</code>, it will save the report's temporary Java source file on disk,
  302. in the specified <code>tempdir</code>. This is useful for debugging report expressions in certain cases.
  303. <br>
  304. <br>
  305. Depending on the report expression language they are mapped to, other report compiler implementations might produce script files instead of Java files,
  306. for report expression evaluation. The <code>keepjava</code> and the <code>tempdir</code> attributes will still work for them, except that the files
  307. that will be kept into the temporary location will not be Java source files but script files, also helpful for debugging.
  308. </span></td>
  309. </tr>
  310. <tr>
  311. <td colspan="5">
  312. <br>
  313. </td>
  314. </tr>
  315. <tr>
  316. <td align="right" colspan="5"><a name="antdecompile"></a><a class="toc" href="#top">top</a></td>
  317. </tr>
  318. <tr>
  319. <td colspan="5">
  320. <hr size="1">
  321. </td>
  322. </tr>
  323. <tr valign="top">
  324. <td><img border="0" src="../../resources/jr-16x16.png"></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>
  325. </tr>
  326. <tr>
  327. <td colspan="5">
  328. <br>
  329. </td>
  330. </tr>
  331. <tr valign="top">
  332. <td>
  333. <br>
  334. </td><td nowrap="true"><span class="label">Description / Goal</span></td><td>
  335. <br>
  336. </td><td colspan="2"><span class="description">
  337. How to re-create the JRXML source files for multiple compiled report templates using the Ant build tool.
  338. This is useful in cases where only the compiled <code>*.jasper</code> files of older reports are available,
  339. the initial <code>*.jrxml</code> source files being lost.
  340. </span></td>
  341. </tr>
  342. <tr valign="top">
  343. <td>
  344. <br>
  345. </td><td colspan="1"><span class="label">Since</span></td><td>
  346. <br>
  347. </td><td colspan="2"><span class="description">3.7.1</span></td>
  348. </tr>
  349. <tr>
  350. <td colspan="5">
  351. <br>
  352. </td>
  353. </tr>
  354. <tr>
  355. <td>
  356. <br>
  357. </td><td colspan="4"><span class="description">
  358. [Under Construction]
  359. </span></td>
  360. </tr>
  361. <tr>
  362. <td colspan="5">
  363. <br>
  364. </td>
  365. </tr>
  366. </table>
  367. <br>
  368. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  369. <tr>
  370. <td>
  371. <hr size="1">
  372. </td>
  373. </tr>
  374. <tr>
  375. <td align="center"><span style="font-decoration:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:8pt;font-style:normal;color:#000000;">&copy; 2001-2010 Jaspersoft Corporation <a style="color:#000000;" target="_blank" href="http://www.jaspersoft.com">www.jaspersoft.com</a></span></td>
  376. </tr>
  377. </table>
  378. </body>
  379. </html>