我们之前使用下面的代码设置BIRT Engine在我们的servlet中使用,迁移指南说你只需要将BIRT jar添加到类路径中,BIRT jar被添加到WEB-INF \ lib。
当我们现在运行应用程序时,IReportEngineFactory
返回null。任何帮助表示赞赏。
public static synchronized IReportEngine getBirtEngine(ServletContext sc) throws Exception {
EngineConfig config = new EngineConfig();
config.setBIRTHome("");
config.setLogConfig("C:/Temp", Level.FINEST);
config.setLogFile("birtLog.log");
realPath = sc.getRealPath("/reports");
log.info("Server Info: " + sc.getServerInfo());
log.info(" Servlet Context Name: " + sc.getServletContextName());
log.info("Real Path: " + realPath);
log.info("#####Creating new Birt Engine#####");
//log.info("Birt Home is: " + config.getBIRTHome());
IPlatformContext context = new PlatformServletContext(sc);
config.setPlatformContext(context);
try {
Platform.startup(config);
//log.info("Birt Home is: " + config.getPlatformContext().toString());
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject
(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
birtEngine = factory.createReportEngine(config);
}
catch (Exception e ) {
throw e;
}
return birtEngine;
}
答案 0 :(得分:0)
添加以下行解决了我的自定义BirtEngine.java配置中的问题:
IPlatformContext context = new PlatformServletContext(sc);
config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "");
答案 1 :(得分:0)
在我读过的网上很多帖子中,你不能再设置BIRT主页和平台上下文了。所以你的代码应该是这样的:
public static synchronized IReportEngine getBirtEngine() throws Exception {
EngineConfig config = new EngineConfig();
config.setLogConfig("C:/Temp", Level.FINEST);
config.setLogFile("birtLog.log");
try {
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject
(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
birtEngine = factory.createReportEngine(config);
}
catch (Exception e ) {
throw e;
}
return birtEngine;
}