Question

I am new to iReport trying to learn something interesting in Java. I am using Netbeans 7.1 and installed the required iReport plugins.
I am able to design my first basic report using MySQL table and also able to preview it.

I found 2 file added to my project-
1. report1.jrxml
2. report1.jasper

I understood about .jrxml this file is for raw file of my report where I'm designing and configuring my report. But what is for .jasper?

any one give some idea about this file.

Was it helpful?

Solution

The .jasper file is a compiled report and you can simply load the report for use with

(JasperReport) JRLoader.loadObject(inputStream of .jasper)

while the .jrxml is an xml file suitable for use with a report designer like IReport. You can use .jrxml from within an application directly, but this requires a different call:

 JasperCompileManager.compileReport(inputStream of .jrxml);

Also, note that compileReport can fail if no java compiler is available on the machine (e.g. it will work with it an installed JDK, but may fail with a JRE).

In short the .jasper is the better choice for deployment.

--- EDIT --- This is outside the scope of the original question, but well...

To make your application create a report as you seem to want from the comments, these are the basic steps:

1 Write an ActionListener to respond to button clicks.

2 Write an implementation of JRRewindableDataSource (or find and modify an example).

3 Wire your ActionListener to query the DB as desired and put the results into your data source. Then load the report from .jasper and print the report (you need to create an instance of JRExporter, e.g. JRPrintServiceExporter for printing) and provide it with all the info (printer, report, datasource) then call exportReport() of the JRExporter.

This will require about a few hundred lines of code. I highlighted only the essential key points. Filling in the details shouldn't pose a major problem, but it will require some effort.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top