JasperReports is an open-source Java reporting engine. This Java class library offers reporting capabilities for your application. This Reporting tool helps you to deliver rich content onto the screen, to the printer, or into HTML, PDF, XLS, RTF, CSV, XML, ODT, and TXT files.
In this Jasper Reports tutorial, you will learn:
- What is Jasper Reports?
- Jasper Reports- Environment Setup
- Why use Jasper Reports?
- Life-cycle of JasperReports
- Features of Jasper Reports
- Jasper vs. Pentaho
- Creating a Report Template Example
- Challenges faced while creating JasperReports
- Disadvantages of using Jasper Reports
Step 1) Click on Download Now option to install Jasper Reports Community edition.
Step 2) Select Jaspersoft Studio CE
Step 3) Click on Download button open the download TIB_js-studiocomm_6.9.0_windows_x86_64.exe file.TIB_js-studiocomm_6.9.0_windows_x86_64.exe
Step 4) Following screen will appear, select the I agree button.
Step 5) In the Next Dialog box click on Next button
Step 6) You will see the progress in the next screen.
Step 7) In the next screen, click on the finish button.
Step 8) Following screen will appear in your window.
Step 9) Click on Get started option.
Step 10) Following screen will appear you can start working with Jasper Reports studio.
Here, are many reasons for using a Jasper report tool:
- It offers report generation performance and delivery to users.
- It helps you to represent your data in textual or graphical format.
- It is a standalone and embedded reporting server for reporting compilation and execution.
- It allows role-based access control to all reports in the repository.
- A spring security framework for integration with in-house authentication systems
- It offers secure, schedule, and automatic delivery interactive reporting engine.
- You can embed reports into Java or non-Java Application.
- Various formats of reports can be exported.
- Developers can supply data in multiple ways.
- It can generate watermarks that are laid over the primary image.
- It offers a complete set of SOAP, REST, and Web Services.
- It allows you to use single report data from multiple data sources.
Following are General flow of Life cycle of Jasper Reports:
Designing the report:
This will be the first step where we create the JRXML file. It is the file is a simple XML document which defines the report layout. You can develop this file using any text editor, or report designer.
However, if you are using the report designer, we can visualize the layout of the report, and the real structure of the JRXML should be ignored.
Compiling the report:
In this life cycle stage, the JRXML which is built in the first stage is compiled, and a binary object called the Jasper file (file with jasper xtn) is generated.
This compilation is done to get better performance during execution. These generated Jasper files should be shipped along with your application to run the reports.
Executing the report:
In this stage, the data from the application is gathered and filled in the compiled report format. There is a class called net.sf.jasperreports.engine.JasperFillManager which offers functions to fill the data in the reports.
The output will be stored in Jasper print file (file with jprint xtn) which can be used to print or export the report.
Exporting the report to the desired format:
In this last stage, you need to export the Jasper print file which is created earlier into any format using the class JasperExportManager. As Jasper offers multiple formats of exports, we can use the same input to create various representations of the data.
Here, are Important Features of Jasper Reports tool:
- Offers flexible report layout.
- Developers can supply data in multiple ways.
- It allows you to accept data from multiple data sources.
- Watermarks can also be applied.
- Multiple data sources can be used to transfer data.
- You can generate subreports
- It can generate subreports.
- It helps you to export reports in a variety of formats like PDF, HTML, RTF, Microsoft Excel files.
- The engine allows report definitions to include charts.
Here are major differences between Jasper and Pentaho:
|Reports||Jasper uses a report for designing the reports.||It used the Pentaho Report Designer.|
|ETL support||Jaspersoft uses Talend Open Studio version for ETL purpose.||It uses Pentaho Data Integrator as a default ETL tool.|
|Dashboard||Dashboard functionality is present only in the Enterprise editor of Jaspersoft.||Pentaho offers wide ranges of features in their dashboards.|
|Mobile Business Intelligence||Jaspersoft has better mobile BI too.||Pentaho used need to rely on a third-party tool to enhance mobile BI experience.|
|Documentation||Better marketing, sites, and documentation.||Documentation support is poor.|
|Best feature||Easier to research and find what you need.||Offers Data mining and iPhone integration|
|Paid version||The paid version offers features like ad hoc query web Ul, dashboard creation web Ul.||Offers feature like LDAP integration, SSO, auditing, etc.|
The report template file used in JasperReports is a simple XML file having jrxml extension. This file contains the tag as its root element. JasperReports framework can handle different types of data sources.
Report template is designed and created using the following two steps –
Step 1) Creating the JRXML file in Jaspersoft Studio.
- Go to file option.
- Select the New sub-menu
- Click on Jasper Report option.
Step 2) Selecting the desired template.
- Select your template, for example, cherry.
- Click on the "Next" button.
Step 3) Selecting a parent folder.
- Select MyReports folder.
- Enter the file name, for example, "Cherry Report."
- Click on the "Next" button.
Step 4) In Data Source window, click on "New" button to create new data adapter.
Step 5) Selecting a data adapter.
- Select data adapter from the list box. For example, "Collection of JavaBeans."
- Click on the "Next" button.
Step 6) Entering data adapter details and selecting factory class.
- Enter a name for your adapter.
- Select factory class by clicking on the "…" button.
Step 7) Entering prefix or pattern.
- Enter the name prefix or pattern.
- Click matching items.
- Click on the "OK" button.
Step 8) Defining factory class and adding the path to jar files.
- Enter the name of a static method in the factory class. In this example, this is createBeanCollection.
- If your JavaBeans definition has field descriptions, and you would like to use these as names in Jaspersoft Studio, check use field description checkbox.
- Add a path to your jar files.
- Click on "Finish" button.
Step 9) Click on the "Next" button.
Step 10) Congratulations! You have added all necessary report creation information successfully. Click on "Finish" button.
The report will be generated as shown in below screen.
The above file requires to compile into JasperReport Binary format, which is called the jasper file.
The Interface net.sf.jasperreports.engine.design.JRCompiler, which is part of the JasperReports library, plays an important role in the compilation of this report template file.
You can compile a JRXML file in the following two methods:
- Programmatic compilation.
- Compilation using Apache ANT task.
Understanding the different report bands
Following are standard report format adopted by most of the commercial report generating tools.
- Page header
- Column header
- Column footer
- Page footer
Let's Learn each reporting bands in detail:
This band is shown at the starting of the report. It can be used as the first page by setting the attribute
Page header reporting band shown at the beginning of each page. It excludes the first page if the title band is used and the last page if this summary band is used with setting
Column headers appear before the detail band on each page.
Detail section iterated for each record in data source supplied. It also allowed having multiple detail band ( 1, 2, etc.)
This section appears below the detail band on each page where detail band is present. The default setting is the end of the page, but this can be switch to under last detail band by setting the attribute
This section will be displayed at the end of each page excluding summary band, title band, the and last non-summary band.
Last Page Footer:
This section appears on the previous page (if not a summary band is given) in place of normal page Footer.
The summary section only appears at the end of the report on a new page. when
isSummaryNewPage="true" is set and with page header and footer is set
This section only appears when it is defined every time the group expression change before the detail band.
This section only displays if a group is defined every time before the group expression change after the detail band.
It is displayed on all the pages as background to all other reporting bands.
This band will appear when no data source was passed, or the data source is empty and whenNoDataType="NoDataSection" is set.
Here, are a few challenges you will face while creating Jasper Reports:
- Core changes - The business changes or enhancements. It is required to change the core logic of the report.
- Complicated reports - sub-reports and cross-tabs reports are good' example.
- Charts reports or Visual charts, for example, Graph, XY line, Pie, Bar, Time series, and Meter charts.
Here, are drawbacks/cons of using Jasper Reports.
- Once you start making any change with parts of the package and removing features, it's very difficult to get back to the default package setting.
- It's too rigid, editing of lines and creation of cross tabs is a challenging task.
- Some common task, like specifying sub-totals for a grouped report is easier in the other two report designers.
- Jasper requires that you compile reports before running them. This means that report developers must have the entire Java SDK installed.
- Sometimes when you edit the report, it does not show the same preview as it is displayed on the web.
- JasperReports is an open-source Java reporting engine. This Java class library offers reporting capabilities for your application.
- Jasper Reports offers report generation performance and delivery to users.
- Jasper Reports life cycle include 1) designing reports, 2) Compiling reports, 3) Executing the report, and 4) Exporting the report to the desired format.
- In Jasper Reports, you can create multiple data sources to transfer data.
- The major difference between Jasper and Pentaho is that Jasper reports uses a report for designing the reports while Pentaho uses the Pentaho Report Designer.
- The report template file used in JasperReports is a simple XML file having jrxml extension.
- Important Reports bands are: 1)Title 2) Page header 3) Column header 4) Detail 5) Column footer 6) Page footer and, 7) Summary.
- The biggest challenge of using Jasper Reports is that you need to change the core logic of the report if the business logic change.
- The biggest drawback of Jasper Reports is that when you make any change with parts of the package, it's tough to get back to the default package setting.