Integrate the report into a Java application

You created a data source and at least one report design document. You can now package and add the necessary code to launch the report from a Java application.

You have tested your data source and design using the Report Launcher. You now want to integrate the data and report into a bespoke application using code to make the necessary calls. This code will not only run the report, it will also specify the format of the report, how and if the report displays, and where the report is saved on disk.

Package the data source

Up to this point, you have been creating the data source and the methods needed to serialize the data as XML to stream to your report. You now need to provide this to your existing Java application.

It is recommended that you package this as a .JAR file, that you can include in your application.

While not optimal, you could alternatively:
  • Copy the Java code into your application.
  • Reference the Java class files.

Add code to run the report

Add the Java code to your application:
  1. If your data source needs to connect to a database, you need to establish the database connection.
  2. Configure the report.

    In this example, the report is configured to be output to PDF.

    // Configure the report
    FormatHandler handler = new FormatWriter(reportFile);
    PDFRenderer renderer = new PDFRenderer(handler);
    FourRpLayouter report = new FourRpLayouter(reportDesignFile, renderer);
  3. Instantiate the data source object from the data source library.

    In this example, OrderReport is the Java class that provides the data source:

    // Run the report
    OrderReport orderReport = new OrderReport(connection);
  4. Pass the object to the report engine for processing.