0

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.

Alex K
  • 22,315
  • 19
  • 108
  • 236
user2747954
  • 97
  • 1
  • 5
  • 16
  • `Can I use .jasper file?` - Yes, you can. `But what is for .jasper ? ` - It is a compiled *jrxml* file. – Alex K Oct 14 '13 at 16:47
  • You can start learning *JasperReports* with [JasperReports Ultimate Guide](http://jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf) – Alex K Oct 14 '13 at 16:49
  • @Alex K Thank you for clearing my doubt, I was think same. But 1 more query from me- If this is the complied form of jrxml file this means we can view this file on jButton click and no need to compile or ireport pulgins only viewer will be enough for this purpose. But after searching on net for last 2 days I did not found any site where I can any type of tutorial or help on using .jasper file on jButton click event from netbeans. – user2747954 Oct 14 '13 at 16:56
  • You can find a lot of answers on *SO* - try to use search engine on *SO*. For example, you can use [JasperViewer](http://jasperreports.sourceforge.net/api/net/sf/jasperreports/view/JasperViewer.html). The samples on *SO*: [JAVA Reporting Tool iReport](http://stackoverflow.com/q/2452292/876298) & [How to show report with JasperReports API](http://stackoverflow.com/q/9460740/876298) – Alex K Oct 14 '13 at 17:03
  • Maybe you should tell us where the connection between JButton an jasper report is. IMO there isn't any. JR only provides report creation, its *your* task to write the glue code between UI and performing something with a report. So you're likely researching the wrong topic - divide and conquer. Work through the Swing tutorials to learn how to process UI events, then check the JR docs to learn how to work a report. Combine your new knowledge to solve the problem. – Durandal Oct 14 '13 at 17:06
  • I have a jInternalframe where I will enter customer ID, based on that ID my sql will fetch data from MySQL for iReport and generated report should be displayed. This is my plan but as @Durandal said for jrxml compiler is required, but how can I expect compiler will be present on mu friends PC so it is good to use .jasper file. – user2747954 Oct 14 '13 at 17:15
  • @user2747954 Are you familiar with *Java*? – Alex K Oct 14 '13 at 17:20
  • What you're missing here is probably the connection between MySQL and the report. So your best bet is probably to look for tutorials on how to create a report with MySQL as data source. I presume you designed a report, but you also need to have a data source to fill said report. Make divide and conquer your learning/implementing strategy - its *the* most important thing to learn, really. Any non-trivial programming task can be divided into *many small* problems, which can be solved independently. And you will have a much easier time finding a tutorial for each limited, well defined problem. – Durandal Oct 14 '13 at 17:20
  • @AlexKYes but not genius – user2747954 Oct 14 '13 at 17:22
  • @DurandalOK after doing all steps I will come back to you for guidance, if you permit – user2747954 Oct 14 '13 at 17:24
  • @user2747954 You can use [*JasperReports API*](http://jasperreports.sourceforge.net/api/) for compiling *jrxml* files, generating reports in different output formats and showing report. The samples are here: [JasperReports - Sample Reference](http://jasperreports.sourceforge.net/sample.reference.html) – Alex K Oct 14 '13 at 17:29

1 Answers1

1

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.

Durandal
  • 19,919
  • 4
  • 36
  • 70
  • @DurandalThanx a lot for this very confined and exact reply. Can I use .jasper file for parametrized report, means enter customer id at runtime and report will be generated at that time on jButton click. – user2747954 Oct 14 '13 at 17:09
  • @user2747954 See my edit. Its *not trivial*. – Durandal Oct 14 '13 at 17:45
  • If we add JasperReports® Library (https://community.jaspersoft.com/project/jasperreports-library) to the Java Application, we can compile .jrxml file without JDK kit. – Panduka Nandara Aug 29 '18 at 17:02