Thursday, February 7, 2008

Automatic generation of BIRT reports

Automatic generation of BIRT reports is a common task for every company that has reports that should be presented to the customers.

Those reports should be delivered regularly. If howto that I am going to present is available somewhere than I am sorry, but I was not able to find it out and I had to merge knowledgle scattered in a several wiki pages.

But in the ends solution seems to be very easy:

1. Download BIRT runtime and unzip it somewhere. You should have now birt-runtime-2_2_1_1 folder.
2. Set up environment variable to point to that folder either in OS or inside birt-runtime-2_2_1_1\ReportEngine\genReport.bat(sh for linux).
3. Put your jdbc jar file in folder birt-runtime-2_2_1_1\ReportEngine\plugins\\drivers.
4. Execute genReport.bat script to see usage. For all those good computer scientists (and good computer scientist is a lazy one) I present sample command:
genReport.bat -f PDF -o outputfile.pdf -F report_design.rptdesign

I hope it will help somebody.


Virgil said...

Thanks Chris for sharing this tip... I added a pointer to this page from BIRT Exchange


azique said...

As I'm using XML source documents for my reports I had to extend the existing ReportRunner class (found the source code in the BIRT packages online) so I can give the path of this source file as a parameter. And as our customers don't know (or don't want to know) how to set environment variables, I also extended the ReportRunner class so it accepts a parameter for the runtime home path (BIRT_HOME). So now I have two more paraneters -h for birt home and -s for the source to use.
My command now would be
genReprt -h "./ReportEngine" -s source.xml -f PDF -o report.pdf design.rptDesign

Thuy said...

virgil, thank you for sharing tips!

azique, I've been trying to do the same thing with the XML source documents passed in. could you provide more info on how to extends and set -s to take the path of the xml file pls?!?

Thank you!

Alejandro said...

Hi, do you know how can I generate the output to an xml file? I only find that the report engine via command line can generate HTML and PDF.
Thanks in advanced,

azique said...

thuy, sure:

First you have to get the source code of the birt report engine ( go to recent builds page or full download page, and there find "source code")

The next step is, to find the class. I copied it and put the *.java-file in the folder of genReport.bat which is going to start it.

Now you can find the parseRunAndRenderOptions() method and add another if construct for your new option 's'.

Next step is, to actually tell the report to use this xml source file path: find the runAndRenderReport() method

IReportRunnable runnable = engine.openReportDesign(designPath);

ReportDesignHandle reportDesign = (ReportDesignHandle) runnable.getDesignHandle();

SlotHandle dataSourceSlotHandle = reportDesign.getDataSources();

OdaDataSourceHandle dataSource = null;
// set the path to the xml source file
dataSource = (OdaDataSourceHandle) (dataSourceSlotHandle.get(0));
dataSource.setProperty("FILELIST", sourcePath );

Also change the printUsage() method so it tells the user about the new options.

The last step is, to use this modified class in the genReport.bat:

%JAVACMD% -cp "%BIRTCLASSPATH%" -DBIRT_HOME="%BIRT_HOME%\ReportEngine" ModifiedReportRunner %p1% %p2% %p3% %p4% %p5% %p6% %p7% %p8% %p9% %p10% %p11% %p12% %p13% %p14% %p15% %p16% %p17% %p18% %p19%

marcSmci said...

azique, can You post the source code You have modified, pls ? This will be a great help for me !


azique said...

Hi Marc,

I found out that using parameters for the data source does the same with less effort! So you don't need to alter the ReportRunner class but can change your report design data source to bind to a parameter which you start the ReportRunner with:

genReport -p "dataSource=D:\data\source.xml" -f PDF -o report.pdf design.rptDesign

marcSmci said...

Well done, azique ;-) Running for me !


7akub said...

nice, but i have problem to make some raport can sent me how can i do it ? when i write gerReport.bat.... only show me rules about make raport. i ca give u mine mail and u sent me in polish language how can i do it?

Radim said...

syntax for command line has changed:
genReport.bat --format HTML l.rptdesign

Horton said...

I want to generate BIRT Report on UML Model through command line.

Command i am writing is:
genReport.bat -p "dataSource=D:\ArchitectureModel.
emx" -f PDF -o report.pdf ComprehensiveMetricReport.rptdesign

Result: A Report with no data gets generated.

Kindly suggest how I can rectify problem.


kuna said...

Will you please tell me how to pass multiple values from listbox as report parameter for "Automatic generation of BIRT reports".I am fetching data from databse and using mysql.

சமுகன் said...

Is there any option to make the design on the jsp page for the report.That is i need to design a report on a web page while the application is running. I'm using BIRT. Kindly do the needful