题
我是 BIRT 新手,我正在尝试使报表引擎运行。我正在使用中提供的代码片段 http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php
但我有一个奇怪的例外:
java.lang.assertionerror at org.eclipse.birt.core.framework.platform.startup(platform.java:86)
并且日志文件中没有任何内容。
也许我在配置中遗漏了一些东西?有人可以给我一些提示,告诉我可以尝试如何让它运行吗?
这是我正在使用的代码:
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( );
}
}
解决方案
只是一个想法,但我想知道您在设置记录器时使用正斜杠是否会导致问题?代替
config.setLogConfig("d:/temp", Level.FINEST);
你应该使用
config.setLogConfig("/temp", Level.FINEST);
或者
config.setLogConfig("d:\\temp", Level.FINEST);
最后,我意识到这只是一些示例代码,但您肯定希望将平台启动代码从运行和渲染任务中分离出来。平台启动非常昂贵,每个会话只能启动一次。
我有几个在 Subversion 服务器中设置的 Eclipse 项目,它们演示了如何使用报表引擎 API (REAPI) 和设计引擎 API (DEAPI),当您的代码变得更加复杂时,您可能会发现它们很有用。
要获取示例,您需要 Subclipse 或 Subversive 插件,然后需要连接到以下存储库:
http://longlake.minnovent.com/repos/birt_example
您需要的项目是:
birt_api_example
birt_runtime_lib
script.lib
您可能需要调整 BirtUtil 类中的某些文件位置,但我认为大多数文件位置都是相对路径。有关如何使用示例项目的更多信息,请访问我的博客:http://birtworld.blogspot.com。特别是这篇文章应该有帮助: 报告的测试和调试
其他提示
几个月前我也犯了同样的错误。我不太确定到底是什么解决了它,但我的代码如下所示:
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);
也许您可以通过比较此代码片段和您自己的代码来解决您的问题。顺便说一句,我的 PATH_TO_ENGINE_HOME 是“/WEB-INF/platform”。[编辑]我使用了 birt-runtime-2_1_1 的 WebViewerExample 中的完整“平台”文件夹。atm birt-runtime-2_3_0 是实际的。[/编辑]
如果这没有帮助,请提供更多详细信息(例如代码片段)。