BIRT Runtime Engine API的AssertionError
我是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( ); } }
解决方案
回答
几个月前,我犯了同样的错误。我不太确定实际修复了什么,但是我的代码如下所示:
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"。 [edit]我使用了birt-runtime-2_1_1的WebViewerExample中完整的"平台"文件夹。 atm birt-runtime-2_3_0是实际的。[/ edit]
如果这样做没有帮助,请提供更多详细信息(例如代码段)。
回答
只是一个想法,但是我想知道我们是否在设置记录器时使用正斜杠会引起问题?代替
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。特别是,本文应该对以下方面有所帮助:报告的测试和调试