AssertionError with BIRT Runtime Engine API
Question
I'm new to BIRT and I'm trying to make the Report Engine running. I'm using the code snippets provided in http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php
But I have a strange exception:
java.lang.AssertionError at org.eclipse.birt.core.framework.Platform.startup(Platform.java:86)
and nothing in the log file.
Maybe I missed something in the configuration? Could somebody give me a hint about what I can try to make it running?
Here is the code I'm using:
public static void executeReport()
{
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("D:\\birt-runtime-2_3_0\\ReportEngine");
config.setLogConfig("d:/temp", Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("D:\\birt-runtime-2_3_0\\ReportEngine\\samples\\hello_world.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/resample/Parmdisp.html");
options.setOutputFormat("html");
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
Platform.shutdown( );
}
}
Solution
Just a thought, but I wonder if your use of a forward slash when setting the logger is causing a problem? instead of
config.setLogConfig("d:/temp", Level.FINEST);
you should use
config.setLogConfig("/temp", Level.FINEST);
or
config.setLogConfig("d:\\temp", Level.FINEST);
Finally, I realize that this is just some sample code, but you will certainly want to split your platform startup code out from your run and render task. The platform startup is very expensive and should only be done once per session.
I have a couple of Eclipse projects that are setup in a Subversion server that demonstrate how to use the Report Engine API (REAPI) and the Design Engine API (DEAPI) that you may find useful as your code gets more complicated.
To get the examples you will need either the Subclipse or the Subversive plugins and then you will need to connect to the following repository:
http://longlake.minnovent.com/repos/birt_example
The projects that you need are:
birt_api_example
birt_runtime_lib
script.lib
You may need to adjust some of the file locations in the BirtUtil class, but I think that most file locations are relative path. There is more information about how to use the examples projects on my blog at http:/birtworld.blogspot.com. In particular this article should help: Testing And Debug of Reports
OTHER TIPS
I had the same mistake a couple of month ago. I'm not quite sure what actually fixed it but my code looks like the following:
IDesignEngine engine = null;
DesignConfig dConfig = new DesignConfig();
EngineConfig config = new EngineConfig();
IDesignEngineFactory factory = null;
config.setLogConfig(LOG_DIRECTORY, Level.FINE);
HttpServletRequest servletRequest = (HttpServletRequest) FacesContext.getCurrentInstance()
.getExternalContext().getRequest();
String u = servletRequest.getSession().getServletContext().getRealPath("/");
File f = new File(u + PATH_TO_ENGINE_HOME);
log.debug("setting engine home to:"+f.getAbsolutePath());
config.setEngineHome(f.getAbsolutePath());
Platform.startup(config);
factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
engine = factory.createDesignEngine(dConfig);
SessionHandle session = engine.newSessionHandle(null);
this.design = session.openDesign(u + PATH_TO_MAIN_DESIGN);
Perhaps you can solve your problem by comparing this code snippet and your own code. btw my PATH_TO_ENGINE_HOME is "/WEB-INF/platform". [edit]I used the complete "platform"-folder from the WebViewerExample of the birt-runtime-2_1_1. atm birt-runtime-2_3_0 is actual.[/edit]
If this doesn't help please give a few more details (for example a code snippet).