Birt Development Experience

Source: Internet
Author: User
Tags zip

Birt Summary

First, the report template design environment

1. Download the design environment for the report using the following URL:

http://download.eclipse.org/birt/downloads/

Download the Birt-report-framework-2.1.2.zip file to extract the file to the Eclipse installation directory.

2. Download Itext-1.3.jar using the following URL:

Http://prdownloads.sourceforge.net/itext/itext-1.3.jar

3. Copy the Itext-1.3.jar to the Eclipse/plugins/com.lowagie.itext_*/lib directory

Second, the operating environment of the report

1. Download the operating environment in http://download.eclipse.org/birt/downloads/: Birt-runtime-2.1.2.zip

Unzip the Birt-runtime-2.1.2.zip, copy all the files under Birt-runtime-2_1_2/reportengine/lib to the web-inf/lib/directory in the Web app, Copy the downloaded Itext-1.3.jar to that directory as well.

2. To set up the Enginehome using the report API, run the following code:

Engineconfig config = new Engineconfig ();

Config.setenginehome ("Birthomepath");

Where Birthomepath is the/birt-runtime-2_1_2/reportengine directory

3. Select the application tag in the server configuration and modify the value of the Web app's ClassLoader mode to: Parent_last, into the diagram:

4. Reference Code snippet:

Engineconfig config = new Engineconfig ();

Config.setenginehome ("E:/reportengine");

Reportengine engine = new Reportengine (config);

if (engine==null) {

SYSTEM.OUT.PRINTLN ("null");

}

Ireportrunnable Design=null;

try {

Design =

Engine.openreportdesign (

"E:/workspace/testreport/testreport.rptdesign");

} catch (Engineexception e) {

TODO auto-generated Catch block

E.printstacktrace ();

}

Irunandrendertask task = engine.createrunandrendertask (design);

Htmlrenderoption options = new Htmlrenderoption ();

Options.setoutputfilename ("C:/customers.pdf");

Options.setoutputformat ("PDF");

Task.setrenderoption (options);

try {

Task.run ();

} catch (Engineexception E1) {

TODO auto-generated Catch block

E1.printstacktrace ();

}

Engine.destroy ();

Iii. Dynamic configuration of report data sources

1. Select the data Sources option under the Data Explore tab and select the datasource you want to configure

2. Select the Beforeopen event and enter the following reference code:

Importpackage (Packages.java.io);

Importpackage (Packages.java.util);

Fin = new Java.io.FileInputStream (New String ("E:/config.txt"));

props = new Java.util.Properties ();

Props.load (Fin);

Extensionproperties.odaurl = new String (props.getproperty ("url"));

Extensionproperties.odadriverclass = new String (Props.getproperty ("Driver"));

Extensionproperties.odauser = new String (Props.getproperty ("userid"));

Extensionproperties.odapassword = new String (Props.getproperty ("password"));

Fin.close ();

Write data source configuration information in E:/config.txt, for example:

Url=jdbc:mysql://localhost:3306/test

Driver=com.mysql.jdbc.driver

Userid=root

password=111111

3. The path to the data source configuration file in the code above can be passed in as a parameter. Modify the following:

Fin = new Java.io.FileInputStream (New String (params["Propdir"));

To add a report parameter in a report file Propdir

Iv. passing parameters to the report

1. Set query parameters for a dataset (Parameters for SQL statements)

Double-click the dataset you want to edit, and write the SQL statement: Figure:

SQL statements. Set the query parameters, double-click the Parameters option in the dataset to add parameters, as shown:

The Add parameter panel, linked to report parameter, refers to whether the query parameters of the dataset are to correspond to the reporting parameters. The general selection and the defined report parameters correspond.

2. If 3 parameters (Pcity,ppname,propdir) are defined in the report, see figure:

Use the API provided by Birt to write the following code:

Ireportrunnable Design=null;

try {

Design = Engine.openreportdesign ("E:/workspace/testreport/testreport.rptdesign ");

} catch (Engineexception e) {

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.