javabirtbirt-emitter

BIRT csv emitter plugin error -


I am trying to get a CSV from the report using this well-known plugin and the example from its documentation, but it throws an exception. I wonder why, because I just copied most of the code from the doc.

My code is:

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

I am getting the exception:

    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

I found the package org.eclipse.core.runtime and registered in the build path, but then I am getting the same exception. Indeed, there are no any CoreException.class in the org.eclipse.core.runtime package. What am I doing wrong?


Solution

  • I was trying a lot of variants of importing different jars, but finally i found the weird decision here:

    go to the Project Explorer, right-mouse click on properties for the project, go to Java Build path, Click on the External Jars button, then select all the libraries under C:\birt_runtime\birt-runtime-2_1_0\ReportEngine\lib\ folder

    This made chaos there, but at least it starts.