import org.eclipse.birt.core.framework.Platform; import org.eclipse.birt.report.engine.api.EngineConfig; import org.eclipse.birt.report.engine.api.HTMLRenderOption; 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.eclipse.birt.report.engine.api.RenderOption; import java.util.Hashtable; import java.util.Map; public class tester { // private EngineConfig config = null; private String birtHome = "C:/birt-runtime-2_2_2"; private String deployDir = "C:/tester"; private EngineConfig configureEngine() { EngineConfig config = new EngineConfig(); config.setBIRTHome(birtHome + "/ReportEngine"); return config; } private void configureParameters(IRunAndRenderTask task, Hashtable params) { for (Map.Entry entry : params.entrySet()) { task.setParameterValue(entry.getKey(), entry.getValue()); } } private HTMLRenderOption configureHtmlOutput(String name) { HTMLRenderOption options = new HTMLRenderOption(); options.setOutputFileName(deployDir + "/" + name + ".html"); options.setOutputFormat("html"); options.setEmbeddable(true); options.setImageDirectory("images"); return options; } private void outputReport(RenderOption options, IRunAndRenderTask task) { task.setRenderOption(options); try { task.run(); } catch (Exception e) { System.out.println(e.getMessage()); } finally { System.out.println("finally"); task.close(); } } public void createHtmlReport(String reportName) { createHtmlReport(reportName, new Hashtable()); } public void createHtmlReport(String reportName, Hashtable parameters) { System.out.println("Generating " + reportName); try { EngineConfig config = configureEngine(); Platform.startup(config); IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); IReportEngine engine = factory.createReportEngine(config); IReportRunnable design = engine.openReportDesign(deployDir + "/" + reportName + ".rptdesign"); System.out.println(design.getReportName()); IRunAndRenderTask task = engine.createRunAndRenderTask(design); configureParameters(task, parameters); HTMLRenderOption options = configureHtmlOutput(reportName); outputReport(options, task); engine.destroy(); System.out.println("done"); } catch (Exception ex) { System.out.println(ex.getMessage()); } finally { Platform.shutdown(); } } /** * @param args */ public static void main(String args[]) { /* * Thanks for taking the time to look at this! The createHTML method * shown below will take a string that is the report name not including * the extension (extension is added in class) and will look for it in * C:/tester, the output will also be sent to this directory. If all * goes well, the first report should generate and the rest fail. Note * using mysql connector 5.1.6. Thank you! John */ for (int i = 0; i < 3; i++) { tester r = new tester(); r.createHtmlReport("new_report"); } } }