tumblr counter

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








37 Responses to “Call Jasper Report / Ireport From Java Application”
  1. pradhumna 09.07.2012 18:48:42
  1. Coolashy1510 10.07.2012 18:51:21
  1. admin 11.07.2012 17:49:22
  1. Sherin Matheew 11.07.2012 18:53:12
  1. Swapnil Shirsat 24.08.2012 12:03:30
  1. admin 24.08.2012 17:03:58
  1. Swapnil Shirsat 24.08.2012 19:03:02
  1. DeD 12.09.2012 18:34:30
  1. admin 14.09.2012 17:53:07
  1. Hardik Mishra 16.09.2012 18:31:25
  1. admin 18.09.2012 18:32:35
  1. haris 25.09.2012 18:28:39
  1. admin 26.09.2012 18:27:42
  1. somphas 21.11.2012 18:37:52
  1. Felipe 04.09.2013 14:43:22
  1. dipesh bhavsar 08.10.2013 04:38:48
  1. chitra 21.10.2013 00:55:31
  1. admin 21.10.2013 23:28:27
  1. prabhu 12.11.2013 01:36:13
  1. admin 14.11.2013 02:19:01
  1. Prasad 20.01.2014 11:26:31
  1. admin 25.01.2014 00:06:56
  1. iman 03.03.2014 04:46:38
  1. admin 03.03.2014 11:20:58
  1. iman 04.03.2014 04:12:37
  1. Asim 10.07.2014 16:46:39
  1. admin 11.07.2014 08:27:13
  1. senn2007 24.07.2014 20:01:58
  1. admin 04.11.2014 15:09:25
  1. Sasindu 17.11.2014 12:15:54
  1. admin 17.11.2014 20:15:52
  1. Javier 09.01.2015 07:59:03
  1. admin 09.01.2015 21:46:34
  1. Javier 09.01.2015 23:54:38
  1. Javier 09.01.2015 23:56:03
  1. Javier 14.01.2015 05:40:49
  1. Mahendra 16.04.2015 17:17:08

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