- JasperReports 3.5 for Java Developers
- David R. Heffelfinger
- 1202字
- 2021-04-01 13:58:23
JasperReports class library
For all JasperReports-related tasks, we need to add the JasperReports library to our CLASSPATH. The JasperReports library can be found under the dist
directory in the project file; it is named jasperreports-3.5.2.jar
. Depending on the version of JasperReports, the filename will vary.
Required libraries for report compilation
The project file described earlier contains all of the required supporting libraries. Once that file is downloaded, all the required libraries can be found under the lib
subdirectory of the directory created when extracting the ZIP file. JasperReports uses these required files for XML parsing. Therefore, they are needed when compiling JRXML files programmatically, not for filling or displaying reports. JRXML files can be compiled using a custom ANT task provided by JasperReports. If we choose to compile our JRXML files using this custom ANT target, these required libraries need to be added to the CLASSPATH variable of the ANT build file. There are example build files included in the project file and also at http://www.packtpub.com/files/code/8082_Code.zip.
Apache Commons is a collection of Java libraries developed and distributed by the Apache Software Foundation. Apache Commons includes libraries and utility classes providing commonly used functionality, thereby freeing developers from re-implementing it. As we can see from the list of libraries we are about to discuss, JasperReports makes extensive use of Apache Commons, and we should as well. When we are about to implement a piece of functionality that is frequently needed, we should make sure that there isn't a Apache Commons library that implements it for us before digging in. Apache Commons includes libraries for logging, XML parsing, sending and receiving email, I/O, network utility classes, and many others. For more information, visit the Apache Commons at http://commons.apache.org/.
The following discussion about libraries highlights the fact that JasperReports makes extensive use of Apache Commons.
The Commons Digester library includes utility classes used to initialize Java objects from XML files. JasperReports takes advantage of the Digester component of the Apache Commons repository to implement its XML parsing functionality. Version 3.5.2 of the JasperReports project ZIP file includes version 1.7 of Commons Digester. The filename is commons-digester-1.7.jar
, and it must be on your CLASSPATH for your JasperReports application to work correctly.
If you downloaded the bare JasperReports class library, you will need to download Commons Digester separately from http://commons.apache.org/digester/.
Another component of the Apache Commons suite is the Collections component. This component provides functionality to complement and augment the Java Collections framework. JasperReports takes advantage of the Collections component of Apache Commons to implement some of its functionality. Like all required libraries included in the project ZIP file, the Commons Collections library can be found under the lib
subdirectory of the directory created when extracting the project ZIP file. JasperReports project file version 3.5.2 includes version 2.1 of Commons Collections, distributed as a JAR file named commons-collections-2.1.jar
.
If you have downloaded the bare JasperReports class library, you will need to download Commons Collections separately from http://commons.apache.org/collections/.
Apache Commons Logging is a component of the Apache Commons that provides components to aid developers with sending data to log files. JasperReports takes advantage of this component, which can be found on the lib
directory of the project ZIP file. The version included with JasperReports 3.5.2 is Commons Logging 1.0.2. The file to be added to your CLASSPATH is commons-logging-1.0.2.jar
.
If you have downloaded the bare JasperReports class library, you will need to download Commons Logging separately from http://commons.apache.org/logging/.
The last library that JasperReports requires for compiling reports is Apache Commons BeanUtils. BeanUtils is a library that provides easy-to-use wrappers around the Java reflection and introspection APIs. Version 3.5.2 of the JasperReports project ZIP file includes BeanUtils 1.8; the file to add to your CLASSPATH is commons-beanutils-1.8.jar
.
If you have downloaded the bare JasperReports class library, you will need to download Commons BeanUtils separately from http://commons.apache.org/beanutils/.
Optional libraries and tools
There are a number of libraries that are required only if we wish to take advantage of some of JasperReports' features. These optional libraries and their uses are listed next.
JasperReports comes bundled with some custom ANT targets for previewing report designs and for viewing reports serialized in JasperReports' native format. Although not strictly necessary, it is very helpful to have ANT available to take advantage of these custom targets.
ANT can be downloaded from http://ant.apache.org/.
JDT (Java Development Tools) compiler is the Java compiler included with the Eclipse IDE. The JDT compiler is needed only if the JasperReports application is running under a Java Runtime Environment (JRE) and not under a full JDK.
When creating reports, JasperReports creates temporary Java files and compiles them. When using a JDK, JasperReports takes advantage of tools.jar
for this functionality. As a JRE does not include tools.jar
, the JDT compiler is needed. The JasperReports project file version 3.5.2 includes version 3.1.1 of the JDT compiler. It can be found under the lib
directory of the directory created when extracting the project ZIP file. The file to add to your CLASSPATH is jdt-compiler-3.1.1.jar
.
This file cannot be downloaded separately; therefore, if we need to execute our code under a JRE. We need to download the JasperReports project ZIP file because it includes this file needed for report compilation.
When using a JDBC datasource, which is the most common datasource for JasperReports generated reports, the appropriate JDBC driver for our specific RDBMS is needed. The following table lists popular relational database systems and the required JAR files to add to the CLASSPATH. The exact filenames may vary depending on the version, target JDK, and supported JDBC version. The filenames shown here reflect the latest stable versions targeted to the latest available JDK and the latest available version of JDBC at the time of writing.

iText is an open source library for creating and manipulating PDF files. It is needed in our CLASSPATH only if we want to export our reports to PDF or RTF format. Version 3.5.2 of the JasperReports project file includes iText version 2.1.0; the file to add to your CLASSPATH is iText-2.1.0.jar
.
The iText library can be downloaded separately from http://www.lowagie.com/iText/.
JFreeChart is an open source library for creating professional looking charts, including 2D and 3D pie charts, 2D and 3D bar charts, and line charts. It is needed in our CLASSPATH only if we intend to add charts to our reports. JFreeChart 1.0.12 can be found on the lib
directory inside the JasperReports project file version 3.5.2. The file to add to the CLASSPATH is jfreechart-1.0.12.jar
.
JFreeChart can be downloaded separately from http://www.jfree.org/jfreechart/.
JExcelApi is a Java library that allows Java applications to read, write, and modify Microsoft Excel files. We need JExcelApi in our CLASSPATH only if we need to export our reports to XLS format. JasperReports 3.5.2 includes JExcelApi version 2.6. To add XLS exporting capabilities to our reports, the file we need to add to our CLASSPATH is jxl-2.6.jar
.
JExcelApi can be downloaded separately from http://jexcelapi.sourceforge.net/.
- 做合成:Photoshop構圖+透視+紋理+造型+調色技術修煉
- User Training for Busy Programmers
- Zenoss Core Network and System Monitoring
- Rhino 6.0中文版入門、精通與實戰
- 品悟:Alias 2014+Showcase產品可視化造型與渲染
- MATLAB 2015從入門到精通
- iPhone Applications Tune/Up
- Vivado從此開始(進階篇)
- Photoshop插畫藝術火星風暴
- Photoshop CC 2018基礎教程(第3版)
- 計算機輔助翻譯基礎與實訓
- 24小時玩賺剪映
- Drupal 7
- Excel 2010數據處理與分析立體化教程
- 3ds Max-Photoshop游戲模型制作全攻略