ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Deploying BIRT
Pages: 1, 2, 3, 4

Adding the BIRT Report Engine to an RCP Application

The Report Engine download comes with the jars necessary to use the Report Engine API. In addition, it comes with plugins and configuration directories used to launch BIRT plugins that use OSGi. When building an RCP application that needs to run and render reports, using the Report Engine download is not necessary. The Report Engine API is already in plugin format within the Framework download. To use the API in your application, add the dependencies shown in Figure 5.

Dependencies needed to include BIRT Engine in RCP Application
Figure 5. Dependencies needed to include BIRT Engine

These dependencies are enough to compile Report Engine API code. To run the application, see the attached launch configuration for the needed plugins.

The attached example is very similar to the previous example. We use an SWT Browser to display the results of the run operation

The factory.createReportEngine method retrieves the report engine handle using the currently created Eclipse Platform. The engine is then used to run and render the report. You will notice that in this example the output is rendered to an output stream. This output stream is then used in the Browser.setText method to display the report, as shown in Figure 6.

private void previewReport() 
             throws EngineException {
    EngineConfig config = new EngineConfig();
    // Create the report engine
    IReportEngineFactory factory = 
              (IReportEngineFactory) Platform
    IReportEngine engine = factory.
                         createReportEngine( config );
    IReportRunnable design = null;

    try {
       // Open a report design - 
       // use design to 
       // modify design, retrieve
       // embedded images etc.
       String report = reportLocation.getText();
       FileInputStream fs = new 
       design = engine.openReportDesign(fs);
       IRunAndRenderTask task = engine.

       // Set Render context to handle url 
       // and image locations
       HTMLRenderContext renderContext = 
                            new HTMLRenderContext();    

       HashMap< String, HTMLRenderContext > 
            contextMap = new 
            HashMap< String, HTMLRenderContext >();
       contextMap.put( EngineConstants.
                 renderContext );                       

       // Set rendering options - 
       // such as file or stream output,
       // output format, whether it is 
       // embeddable, etc
       // Render report to 
       // Byte Array       
       IRenderOption options;
       options = new HTMLRenderOption( );
       ByteArrayOutputStream bos = 
                   new ByteArrayOutputStream();


       // run the report and destroy the engine


       //set Browser text accordingly
   } catch (Exception e) {

Example RCP Application with BIRT Engine Embedded
Figure 6. Example RCP Application with BIRT Engine Embedded


The intent of this article is to illustrate deployment models available to the BIRT developer. The BIRT project thrives on community feedback, so please feel free to post your comments or questions in the BIRT news group.


Jason Weathersby is the BIRT Evangelist at Actuate Corporation and a member of the Eclipse Business Intelligence and Reporting Tools (BIRT) Project Management Committee (PMC).

Return to ONJava.com.