Jump to: navigation, search

Simple Execute (BIRT) 2.1

Revision as of 14:07, 4 October 2007 by Scottr.innoventsolutions.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

< To: Integration Examples (BIRT)

Simple Execute

This example demonstrate using the RE API to run and render a report design to HTML.

Add comments at the bottom of the example.

BIRT Report Engine API Return to the BIRT Report Engine API examples

BIRT Version

BIRT 2.1.1



import java.util.HashMap;
import java.util.logging.Level;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
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;
public class ExecuteReport {

static void executeReport() throws EngineException
 HashMap<String, Integer> parameters = new HashMap<String, Integer>();

 String name = "Top Count";
       Integer pvalue = new Integer(4);
 parameters.put(name, pvalue);
 IReportEngine engine=null;
 EngineConfig config = null;
  //Configure the Engine and start the Platform
  config = new EngineConfig( );
  config.setEngineHome( "C:/birt-runtime-2_1_1/birt-runtime-2_1_1/ReportEngine" );
  //set log config using ( null, Level ) if you do not want a log file
  config.setLogConfig("c:/birt/logs", Level.FINE);
  Platform.startup( config );
  IReportEngineFactory factory = (IReportEngineFactory) Platform
    .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
  engine = factory.createReportEngine( config );
  engine.changeLogLevel( Level.WARNING );
 }catch( Exception ex){
 //Configure the emitter to handle actions and images
 HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig( );
 emitterConfig.setActionHandler( new HTMLActionHandler( ) );
 HTMLServerImageHandler imageHandler = new HTMLServerImageHandler( );
 emitterConfig.setImageHandler( imageHandler );
 config.getEmitterConfigs( ).put( "html", emitterConfig ); //$NON-NLS-1$
 IReportRunnable design = null;
 //Open the report design
 design = engine.openReportDesign("C:/test/2.1/executereport/test.rptdesign"); 
 //Create task to run and render the report,
 IRunAndRenderTask task = engine.createRunAndRenderTask(design); 
 //Set Render context to handle url and image locataions
 HTMLRenderContext renderContext = new HTMLRenderContext();
 //Set the Base URL for all actions
 //Tell the Engine to prepend all images with this URL - Note this requires using the HTMLServerImageHandler
 //Tell the Engine where to write the images to
 //Tell the Engine what image formats are supported.  Note you must have SVG in the string 
 //to render charts in SVG.
 HashMap<String, HTMLRenderContext> contextMap = new HashMap<String, HTMLRenderContext>();
 contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );
 task.setAppContext( contextMap );
 //Set parameters for the report
 //Alternatively set each seperately
 //task.setParameterValue("Top Count", new Integer(12));
 //Add a scriptable object, which will allow the report developer to put
 //script in the report that references this Java object. eg in script 
 //ProcessFilter pf = new ProcessFilter();
 //task.addScriptableJavaObject("pFilter", pf);
 //Set rendering options - such as file or stream output, 
 //output format, whether it is embeddable, etc
 HTMLRenderOption options = new HTMLRenderOption();
 //Remove HTML and Body tags
 //Set ouptut location
 //Set output format
 //run the report and destroy the engine
 //Note - If the program stays resident do not shutdown the Platform or the Engine
 * @param args
public static void main(String[] args) {
  executeReport( );
 catch ( Exception e )


Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.

In order to compile and run the sample code, you have to make sure that all the necessary libraries are in the classpath. I assume you are using eclipse as your development environment and that you created a java project where you created a java file containing the sample code above. Also you should have downloaded and installed the birt-runtime. (I guess you have because otherwise what did you set the engine home in the code above?)

First of all the question is which libraries do you have to add? The answer is quite easy: All the libraries in the birt-runtime-2_1_1/ReportEngine/lib directory. So all you have to do is to right click the project and choose the properties action to open the project property dialog. There select the "Java Build Path" prperty page. Go to the Libraries tab and add the above mentioned libraries using the "Add external jars ..." button.


Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.