【问题标题】:BIRT csv emitter plugin error -BIRT csv 发射器插件错误 -
【发布时间】:2014-06-18 13:22:28
【问题描述】:

我正在尝试使用this well-known plugin 和其文档中的示例从报告中获取 CSV,但它会引发异常。我想知道为什么,因为我只是从文档中复制了大部分代码。

我的代码是:

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.emitter.csv.CSVRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;

public class RunReport {

    static void runReport() throws FileNotFoundException, BirtException {
        String resourcePath = "C:\\Users\\hpsa\\workspace\\My Reports\\";
        FileInputStream fs = new FileInputStream(resourcePath + "new_report_1.rptdesign");
        IReportEngine engine = null;
        EngineConfig config = new EngineConfig();
        config.setEngineHome("C:\\birtre\\birt-runtime-4_3_2\\");
        config.setLogConfig("C:\\birtre\\", Level.FINE);
        config.setResourcePath(resourcePath);
        Platform.startup(config);
        IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
        engine = factory.createReportEngine(config);
        engine.changeLogLevel(Level.FINE);
        IReportRunnable design = engine.openReportDesign(fs);
        IRunAndRenderTask task = engine.createRunAndRenderTask(design);
        CSVRenderOption csvOption = new CSVRenderOption();
        String format = CSVRenderOption.OUTPUT_FORMAT_CSV;
        csvOption.setOutputFormat(format);
        csvOption.setOutputFileName("newBIRTcsv.csv");
        csvOption.setShowDatatypeInSecondRow(true);
        csvOption.setExportTableByName("SecondTable");
        csvOption.setDelimiter("\t");
        csvOption.setReplaceDelimiterInsideTextWith("-");
        task.setRenderOption(csvOption); 
        task.setEmitterID("org.eclipse.birt.report.engine.emitter.csv");
        task.run();
        task.close();
        Platform.shutdown();
        System.out.println("Report Generated Sucessfully!!");   
    }

    public static void main(String[] args) {
        try {
            runReport();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }  
}

我遇到了异常:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/CoreException
    at org.eclipse.birt.core.framework.Platform.createPlatformLauncher(Platform.java:115)
    at org.eclipse.birt.core.framework.Platform.startup(Platform.java:74)
    at com.demshin.birttest.RunReport.runReport(RunReport.java:26)
    at com.demshin.birttest.RunReport.main(RunReport.java:55)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.CoreException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 4 more

我找到了包 org.eclipse.core.runtime 并在构建路径中注册,但是我得到了同样的异常。实际上,org.eclipse.core.runtime 包中没有任何 CoreException.class。我做错了什么?

【问题讨论】:

  • 我得到了另一个包含所需类的包,但是我需要另一个异常,并且在找到并注册每个新 jar 后需要一个又一个异常。我在这里根本缺少什么?

标签: java birt birt-emitter


【解决方案1】:

不推荐设置引擎主页,并且大多数情况下它会阻止平台启动,例如您的情况。删除这一行:

config.setEngineHome("C:\\birtre\\birt-runtime-4_3_2\\");

您只需要确保 birt 运行时 4.3.2 在您的上下文的类路径中。此外,我建议您先尝试生成原生格式,例如 pdf,然后尝试使用 csv 格式。

【讨论】:

  • 我正在使用 org.eclipse.birt.runtime_4.3.2.v20140225-1404.jar ,是的,我的类路径中有它。有些课程是从那里开始的。我在问问题之前尝试了没有您提到的字符串,但仍然无法正常工作。我也做了 maven 项目。
【解决方案2】:

我尝试了很多导入不同 jar 的变体,但最后我发现了奇怪的决定here

进入项目资源管理器,鼠标右键单击属性 项目,转到 Java Build 路径,单击 External Jars 按钮, 然后选择下的所有库 C:\birt_runtime\birt-runtime-2_1_0\ReportEngine\lib\ 文件夹

这造成了混乱,但至少它开始了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多