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








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

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