run reports outside of iReports

I am very new to Jasper and iReports, but was curious if I build a report with iReports can I run it outside of iReports? i.e. Is there a way to 'export' the entire report/code/etc to some kind of standalone app?

michaelmcginniss's picture
Joined: Aug 11 2006 - 4:27am
Last seen: 16 years 5 months ago

2 Answers:


I have the same problem.
how do you solved it ?

Yousr Bernhard
gramberg's picture
Joined: Mar 8 2010 - 11:13pm
Last seen: 12 years 11 months ago

I'm sure there are many people on this board with more experience than me, but here's my answer, for what it's worth.  YES, you can absolutely run reports outside of iReport.  iReport is intended to be a report authoring environment, not the way an actual end user would run the report.  Two common options for deploying your report once it's written are either (a) use the JasperServer plug-in that allows you to copy your jrxml file to the JasperServer repository so that users of JasperServer can now access a copy of your report, or (b) write some Java (or other?) code that will at a minimum establish a connection to your database, load the .jrxml file, compile it into a .jasper file, "fill" the report, export the report to an appropriate format, and then potentially view the report.  Here's a sample of a (non-production) program that does all that and a little bit more.   You need to import several net.sf.jasperreports files for it to compile:


import java.sql.Connection;
import java.sql.DriverManager;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import java.math.*;
import java.util.*;

public class JasperReportGenerator {
  public JasperReportGenerator() {
  public static Connection connectToDatabase(String databaseName, String userNam
e, String password) {
    Connection connection = null;
    try {
      connection = DriverManager.getConnection(databaseName,userName,password);
    } catch(Exception e) {
      String text = "Could not connect to the database: " + e.getMessage() + " "
 + e.getLocalizedMessage();
    return connection;
  public static void runReport(String databaseName, String userName, String pass
word, String reportFile) throws net.sf.jasperreports.engine.JRException {
//    try {
      Connection connection = connectToDatabase(databaseName, userName, password
System.out.println("Done with connectToDatabase!");
      JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
System.out.println("Done with load!");
      JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesig
System.out.println("Done with compileReport!");
      JRParameter[] jrParameters = jasperReport.getParameters();
      for (JRParameter param : jrParameters) {
System.out.println("Parameter : " + param.getName());
System.out.println("    Class Name: " + param.getValueClassName());
System.out.println("    isSystemDefined: " + param.isSystemDefined());
      HashMap jasperParameter = new HashMap();
      String customTitle = new String("Title from Java Program");
      BigDecimal cutoffAmt = new BigDecimal("5000.00");
      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jaspe
rParameter, connection);
System.out.println("Done with fillReport!");
      JRPdfExporter export = new JRPdfExporter();
System.out.println("Done with setJasperPrint!");
System.out.println("Done with exportReport!");
//      JasperViewer.viewReport(jasperPrint);
// System.out.println("Done with viewReport!");
//   } catch(Exception e) {
//     String text = "Could not create the report " + e.getMessage() + " " + e.g
//      System.out.println(text);
//    }

Post Edited by cbarlow3 at 12/16/2010 16:19
cbarlow3's picture
Joined: Mar 4 2010 - 8:59am
Last seen: 10 months 4 weeks ago