Friday, May 4, 2012

JasperReport – Open Source Java Reporting Framework


Introduction -
JasperSoft is open source Business Intelligence tool. It comes with below components –
  1. JasperReport Library
  2. JasperReport Server
  3. iReport Designer
  4. JasperSoft Studio
  5. JasperSoft ETL
  6. JasperSoft OLAP

Considering the loose coupling between these components, we can use JasperReport Library to generate reports even at the places where we need to generate reports but do not want to setup complete BI tool.

JasperReport Framework.
JasperReport Framework uses jrxml (a type of xml) language to define the design of reports. The Framework comes with jrxml DTD and four below mentioned façade to help in various phases of report generation –
  1. net.sf.jasperreports.engine.JasperCompileManager – JasperCompileManager provide necessary functions to compile the jrxml to jasper file.
  2. net.sf.jasperreports.engine.JasperFillManager – JasperFillManager provides necessary functions to populate the reports with data from various data sources like database or bean etc
  3. net.sf.jasperreports.engine.JasperPrintManager – JasperPrintManager provides necessary functions to get the populated report printed without exporting to a file.
  4. net.sf.jasperreports.engine.JasperExportManager – JasperExportManager provides necessary function to export the populated reports in various file formats like PDF,  Excel, RTF , HTML, XML, CSV etc

Jasper report lifecycle –
JasperReport life cycle consists of following four steps –

  1. Design (jrxml file creation)
  2. Compile (jasper file creation)
  3. Execute (Filling with Data)
  4. Print/Export

Design (jrxml file creation) – JasperReports can be designed either with creating a jrxml file manually or with available design tool. Design tool way should be preferred as manual creation process would be very time consuming. There are following tools available for designing the repots.
  1. JasperAssistant – JasperAssistant comes as eclipse plug-in. Links to install it can view demo is as mentioned below

  1. JasperWave –JasperWave comes as standalone RCP application as well as eclipse plug-in. Links to install and view the demo is as mentioned below

    Download - http://jasperwave.com/download.html
    JasperWave demo - http://jasperwave.com/docs/gettingStarted.html

  1. JasperSoft Studio - JasperSoft Studio comes as eclipse plug-in. Links to install and get a view is as mentioned below.

    Install  - http://jasperforge.org/website/ireportwebsite/JSS%20Website/plugin_install.html?header=project&target=jaspersoftstudio

    View - https://hanichalouati.wordpress.com/2011/05/10/a-quick-tour-around-japsersoft-studio/
  1. iReports – iReport comes as stand alone application as well as plug-in to NetBeans IDE. Links to install and get a view is as mentioned below

    Download - http://jasperforge.org/website/ireportwebsite/IR%20Website/ir_download.html?header=project&target=ireport

    iReport view - http://jasperforge.org/uploads/publish/ireportwebsite/IR%20Website/ir_getting_started.html

Compile (jasper file creation) - To generate the reports jrxml file needs to compile to jasper file. During the compilation process, following steps is performed.
  1. Validation of jrxml file against the jrxml schema
  2. Creation of java file from jrxml file
  3. Compilation of java file to create the class file.
  4. Creation of object of recently created class file.
  5. Serialize the object to .jasper file.

The object created in step4 works as template during the data filling step of report creation.
Jrxml files can be compiled in various ways as mentioned below –
  1. Compilation through java – net.sf.jasperreports.engine.JasperCompileManager provides necessary functions to compile the jrxml file to jasper file. Compilation should be preferred to be done during the build phase of the project unless the report format keeps on changing in runtime.
  2. Compilation through maven – maven compilation of jasper reports should be preferred in maven projects where the report format is pre-decided and does not change on runtime. Sample example is as mentioned below -
    http://mojo.codehaus.org/jasperreports-maven-plugin/examples/example-1.html
  1. Compilation through ant – ant compilation of the jasper reports should be preferred in the ant projects where the report format is pre-decided and does not change on runtime. Sample example is as mentioned below –

Execution (Filling with Data)
net.sf.jasperreports.engine.JasperFillManager provides necessary functions to fill the data in the reports.

Printing/Exporting
net.sf.jasperreports.engine.JasperPrintManager and net.sf.jasperreports.engine.JasperExportManager provide necessary functions to display print the report/exporting in various file formats.

Sample program –
http://java-bytes.blogspot.in/2009/06/jasper-reports-example.html

Maven dependency to include JasperReports –
JasperReports can be easily integrated into the project using the below dependency –
    
   <dependency>  
     <groupId>net.sf.jasperreports</groupId>  
     <artifactId>jasperreports</artifactId>  
     <version>4.1.2</version>  
   </dependency>  

Maven repository hosting Jasper report –
JasperReports projects build is published at the below location –

References
Jrxml schema reference – http://jasperreports.sourceforge.net/schema.reference.html
Sample report views - http://jasperforge.org/website/ireportwebsite/IR%20Website/ir_gallery.html?header=project&target=ireport
JasperReports Documentation -http://jasperforge.org/website/jasperreportswebsite/trunk/documentation.html?header=project&target=jasperreports
JRXML tag reference - http://jasperforge.org/uploads/publish/jasperreportswebsite/JR%20Website/jasperreports_quickref.html
Jasper Report Ultimate Guide - http://www.rcss.org/publication/newsletter/7178531-The-Jasper-Reports-Ultimate-Guide.pdf

2 comments:

  1. Thanks for posting such an excellent informative content.

    ReplyDelete
  2. woah good content! keep it up! (:

    ReplyDelete