Call Jasper Report / Ireport From Java Application

Call Jasper Report / Ireport From Java Application Example describes about How to call Jasper Report and Ireport from a java application.

Jasper-Reports is a free reporting engine that could be written to screen, or to a printer or as HTML, PDF, RTF, Microsoft Excel, XML files, CSV format and ODT files.

Jasper-Report is using in Java related applications, including Web and Enterprise applications, to develop dynamic reports. It reads its instructions from jasper file (compiled) or XML dynamically

We can generate reports using two ways,

1) From "JRXML" (Source) file
2) From "Jasper" (Compiled) file
 

Required Libraries

You need to download

  1. JDK 6
  2. iReport-4.1.1 for designing the report

Following jar must be in classpath (Available from ireport installation directory)

  1. commons-beanutils-1.8.2.jar
  2. commons-collections-3.2.1.jar
  3. commons-digester-1.7.jar
  4. commons-logging-1.1.jar
  5. groovy-all-1.7.5.jar
  6. iText-2.1.7.jar
  7. jasperreports-4.1.1.jar
Note

If you are created a JRXML/Jasper file using a particular version of Ireport (For example consider Ireport-4.7.0)

In order to run the report, you must use same set of jar's available on installed Ireport-4.7.0 directory (C:\Program Files\Jaspersoft\iReport-4.7.0\ireport\modules\ext)

If you are creating a report using Ireport-4.7.0 and compiling / running using Ireport-4.2.0 jar files, you will get java.lang.NullPointerException

1) Create PDF Report From JRXML File

JRXML file is a JasperReports Document. JRXML is the XML file format of JasperReport, which can be coded manually, generated, or created using a tools like IReport, JasperAssistant etc

Execution of report from JRXML file will be very slow, as it need to compile before the execution

import java.io.IOException;
import java.util.HashMap;

import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

// Java Program To Call Jasper Report

public class PdfFromXmlFile {
 
public static void main(String[] args) throws JRException, IOException {
   
   
JasperReport jasperReport = JasperCompileManager.compileReport("report.jrxml");
    JasperPrint jasperPrint = JasperFillManager.fillReport
(jasperReport,new HashMap(), new JREmptyDataSource());
    JasperExportManager.exportReportToPdfFile
(jasperPrint, "sample.pdf");
 
}
}

Output
Call Jasper Report
1 2 Next





39 Responses to "Call Jasper Report / Ireport From Java Application"
  1. pradhumna 2011-10-09 19:06:06.0
  1. Coolashy1510 2011-10-09 19:26:06.0
  1. Sherin Matheew 2011-10-11 17:06:06.0
  1. admin 2011-10-11 19:16:16.0
  1. Swapnil Shirsat 2011-10-19 11:06:16.0
  1. admin 2011-10-21 19:06:46.0
  1. Swapnil Shirsat 2011-10-22 19:06:36.0
  1. DeD 2011-10-23 19:06:06.0
  1. admin 2011-10-24 19:06:06.0
  1. admin 2011-10-25 19:04:06.0
  1. Hardik Mishra 2011-10-25 19:06:26.0
  1. haris 2011-10-26 19:06:06.0
  1. admin 2011-10-27 17:06:06.0
  1. somphas 2011-10-28 19:06:06.0
  1. Felipe 2011-10-29 19:06:06.0
  1. dipesh bhavsar 2011-11-09 19:03:06.0
  1. chitra 2011-11-10 19:06:06.0
  1. admin 2011-11-11 19:06:02.0
  1. prabhu 2011-11-12 19:06:07.0
  1. admin 2011-11-13 14:06:04.0
  1. Prasad 2011-11-15 12:06:06.0
  1. admin 2011-11-16 13:06:03.0
  1. iman 2011-11-16 16:06:06.0
  1. admin 2011-11-16 19:06:09.0
  1. iman 2011-11-19 19:46:06.0
  1. Asim 2011-11-20 19:06:09.0
  1. admin 2011-11-21 19:06:09.0
  1. senn2007 2011-11-22 19:06:09.0
  1. admin 2011-11-23 13:06:09.0
  1. Sasindu 2011-11-25 19:06:09.0
  1. admin 2011-11-26 19:06:29.0
  1. Javier 2011-11-27 19:06:09.0
  1. admin 2011-11-28 19:06:09.0
  1. Javier 2011-11-28 21:06:09.0
  1. Javier 2011-11-28 23:06:09.0
  1. Mahendra 2011-11-29 19:06:09.0
  1. William Tekpeh 2011-11-29 22:06:02.0
  1. admin 2011-11-29 22:16:02.0
  1. Gajendra Solanki 2011-11-29 23:06:02.0

Your email address will not be published. Required fields are marked *