Application-Report Integration

The last step is to integrate the existing report into our java application. This is done with the help of Report Engine API.

Add the libraries from BIRT_HOME/lib to the project. Create the following method in your main application class:

ReportMain.java: main
01public static void main(String[] args) throws BirtException { 02 // create engine configuration 03 EngineConfig config = new EngineConfig(); 04 // specify the path to the BIRT installation 05 config.setEngineHome(BIRT_HOME); 06 // set the output directory for the logging and set the logging level 07 config.setLogConfig(OUTPUT_DIR, Level.FINE); 08 09 // start the Platform to load the plugins 10 Platform.startup(config); 11 // create a factory, which will supply ReportEngine instance 12 IReportEngineFactory factory = (IReportEngineFactory) Platform 13 .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); 14 // there is a significant cost associated with creating a new engine 15 // instance, therefore the application should use only one engine instance 16 // for its reports 17 engine = factory.createReportEngine(config); 18 engine.changeLogLevel(Level.WARNING); 19 20 IReportRunnable design; 21 // Open the report design 22 design = engine.openReportDesign(REPORT_DESIGN); 23 // Create task to run and render the report 24 IRunAndRenderTask task = engine.createRunAndRenderTask(design); 25 26 // Set rendering options - such as file or stream output, 27 // output format, whether it is embeddable, etc 28 HTMLRenderOption options = new HTMLRenderOption(); 29 options.setOutputFileName(OUTPUT_DIR + "//" + REPORT_OUTPUT); 30 // output format can be either html or pdf 31 options.setOutputFormat("html"); 32 task.setRenderOption(options); 33 34 // run the report 35 task.run(); 36 task.close(); 37 38 // shutdown the engine and the platform after use 39 // to clean up and unload the extensions 40 engine.shutdown(); 41 Platform.shutdown(); 42 }

Now you can run the report and check the results in the OUTPUT_DIR folder.