BIRT Report Step By Step Guide

birt reporting guide

BIRT (Business Intelligence and Reporting Tools) is an open-source reporting system that can be used to create reports for various types of data sources. Here is a step-by-step guide to creating a report using BIRT, including code samples:

Steps To Create Report

Install BIRT

First, download and install BIRT from the Eclipse website (https://www.eclipse.org/birt/downloads/). BIRT is a plugin for the Eclipse IDE, so you will need to have Eclipse installed before you can install BIRT.

Create a new report project

Open Eclipse and create a new BIRT Report Project by selecting “File” > “New” > “Project” > “Business Intelligence and Reporting Tools” > “Report Project”. Give your project a name and click “Finish”.

Create a new data source

Right-click on the “Data Sources” folder in the Project Explorer and select “New Data Source”. Choose the appropriate data source type (e.g. JDBC, XML, etc.) and follow the prompts to set up the connection information.

Create a new data set

Right-click on the “Data Sets” folder in the Project Explorer and select “New Data Set”. Choose the appropriate data source from the drop-down list and select the data fields that you want to include in the report.

Create a new report

Right-click on the “Report Designs” folder in the Project Explorer and select “New Report”. Choose the appropriate report type (e.g. blank report,master/detail report, etc.) and click “Next”.

Add data to the report

Drag and drop the data fields from your data set onto the report design canvas to add them to the report. You can also add other report elements, such as text boxes, images, and charts.

Customize report layout and formatting

Use the various formatting options in the “Properties” pane to customize the appearance of your report. You can change font styles, colors, borders, alignment, and more.

Preview the report

To preview the report, right-click on the report design file in the Project Explorer and select “Preview”. This will generate the report based on the data set and show you what the final report will look like.

Export the report

To export the report to a specific format (e.g. PDF, Excel, HTML), right-click on the report design file in the Project Explorer and select “Export”. Choose the desired file format and follow the prompts to export the report.

Example

Here’s an example of a simple BIRT report that displays the number of orders by country:

  1. Create a new report and select a data source.
  2. Drag a table onto the report canvas.
  3. Right-click on the table and select “Edit Data Set”.
  4. Create a new data set and write an SQL query to retrieve the order data, grouping by country.
  5. Drag the “Country” and “Order Count” columns onto the table.
  6. Preview the report to see the results.

Here’s an example of the SQL query for the data set:

SELECT Country, COUNT(*) AS OrderCount
FROM Orders
GROUP BY Country

This will return a result set with two columns: “Country” and “OrderCount”. The BIRT report will display this data in a table, with the country names in one column and the number of orders in another.

Integration with Spring Boot

Now, we will see how to integrating BIRT with Spring Boot:

  1. Add BIRT dependencies to your project
    Add the following dependencies to your Spring Boot project’s pom.xml file:
<dependency>
    <groupId>org.eclipse.birt.runtime</groupId>
    <artifactId>org.eclipse.birt.runtime</artifactId>
    <version>4.8.0</version>
</dependency>

<dependency>
    <groupId>org.eclipse.birt.runtime</groupId>
    <artifactId>viewservlets</artifactId>
    <version>4.8.0</version>
</dependency>
  1. Configure BIRT in Spring Boot
    Create a new Java class to configure BIRT in your Spring Boot project:
import org.eclipse.birt.spring.core.BirtEngineFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BirtConfiguration {

    @Autowired
    private BirtProperties birtProperties;

    @Bean
    public BirtEngineFactory birtEngineFactory() {
        BirtEngineFactory factory = new BirtEngineFactory();
        factory.setBirtHome(birtProperties.getHome());
        return factory;
    }

}

This class creates a new bean for the BirtEngineFactory, which is used to create BIRT report engines. It also injects a BirtProperties object, which contains configuration propertiesfor BIRT.

  1. Create a BIRT report controller
    Create a new Java class to handle requests for BIRT reports:
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class ReportController {

    @Autowired
    private BirtEngineFactory birtEngineFactory;

    @GetMapping("/report/{reportName}")
    public void generateReport(@PathVariable("reportName") String reportName, HttpServletResponse response)
            throws BirtException, EngineException, IOException {
        IReportEngine engine = birtEngineFactory.getObject();
        IReportRunnable report = engine.openReportDesign(reportName);
        IRunAndRenderTask task = engine.createRunAndRenderTask(report);
        task.run();
        response.setContentType(task.getOutputFormat());
        task.render(response.getOutputStream(), null);
        task.close();
    }

}

This class handles requests for BIRT reports by creating a new report engine, opening the report design file, running the report, and renderingthe output to the response object.

  1. Configure BIRT properties
    Create a new Java class to define the properties for BIRT:
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "birt")
public class BirtProperties {

    private String home;

    public String getHome() {
        return home;
    }

    public void setHome(String home) {
        this.home = home;
    }

}

This class defines a property for the BIRT home directory, which is used by the BirtEngineFactory to locate the BIRT engine.

  1. Configure BIRT properties in application.properties
    Add the following properties to your Spring Boot project’s application.properties file:
birt.home=/path/to/birt-runtime-4_8_0/ReportEngine

Replace “/path/to/birt-runtime-4_8_0/ReportEngine” with the path to your BIRT runtime directory.

  1. Run the Spring Boot application
    Start your Spring Boot application and navigate to “/report/your_report_name” in your web browser to generate the BIRT report.

Done. You have successfully integrated BIRT with Spring Boot and can now generate BIRT reports in your web application.

Conclusion

Using open source BIRT for reporting can be a great way to create reports quickly and efficiently. It allows you to create visually appealing reports with a wide range of features and data sources. Additionally, since BIRT is an open source platform, it is free to use and can be customized to fit your needs. Hope this help!

Tags:

3 Replies to “BIRT Report Step By Step Guide”

  1. Hello,
    I’m attempting to follow your guide but I can’t seem to find the propper dependencies for BIRT.
    I’m trying to integrate BIRT in a Spring MVC 6 project (non Spring Boot) and I’ve tried downloading BIRT 4.8.0 directly from the Eclipse website, putting all jar files in WEB-INF > lib and referencing it in Configure Build Path… > Add External JARs…

    However, whenever I try to import org.eclipse.birt.spring.core.BirtEngineFactory; Eclipse doesn’t seem to find anything, despite it actually does resolve other dependencies from the org.eclipse.birt package.

    Additionally, I tried creating a Spring Boot 3.1.1 project and I added the BIRT dependencies that you mentioned above in the pom.xml but Eclipse warns me that there’s a missing artifact and doesn’t resolve them.

    Could you please give me some insight about the BIRT installation process, please? Thank you!

      1. 1. Try cleaning your project (Project > Clean) and then rebuilding it to see if that resolves the issue.
        2. Double-check that you placed all the necessary BIRT jar files in the correct location (WEB-INF/lib)
        3. In Eclipse, go to Project Properties > Java Build Path > Libraries tab. Make sure that the BIRT libraries are listed here. If they are not, you may need to add them manually by clicking “Add JARs” or “Add External JARs” and selecting the BIRT jar files.
        4. try manually importing it using import org.eclipse.birt.spring.core.BirtEngineFactory; in your Java file.

        Also as per the documentation for Non-spring boot based applications https://spring.io/blog/2012/01/30/spring-framework-birt you need to
        add the JAR files from the downloaded BIRT 3.7.1 runtime, birt-runtime-3_7_1\ReportEngine\lib directory, to the WEB-INF/lib of the webapp. You will also need the following JAR files from Spring Framework download in WEB-INF/lib:

        Please check if you are copying correct jar files to WEB-INF/lib

Leave a Reply