从 BIRT 2.5.2 升级到 3.7.1

发布于 2024-12-25 04:51:03 字数 1303 浏览 3 评论 0原文

我们之前使用下面的代码来设置 BIRT 引擎以在我们的 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;
}

We previously used the code below to set up BIRT Engine to use within our servlet, the migration guide says you just need to add the BIRT jars to the classpath, the BIRT jars were added to WEB-INF\lib.

When we run the app now, IReportEngineFactory returns null. Any help is appreciated.

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2025-01-01 04:51:03

添加以下行解决了我的自定义 BirtEngine.java 配置中的问题:

IPlatformContext context = new PlatformServletContext(sc);
config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "");

Adding the following line solved the problem in my custom BirtEngine.java configuration:

IPlatformContext context = new PlatformServletContext(sc);
config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "");
葬花如无物 2025-01-01 04:51:03

在网上的许多帖子中,我读到您不能再设置 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;
}

On many posts in the net I read you must not set BIRT home and platform context anymore. So your code should become something like this:

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文