简体   繁体   中英

Eclipse Birt ClassNotFoundException

I created scripted dataset in Birt (4.4.0) along with a Event Handler:

public class ActionsPerDateDataSet extends ScriptedDataSetEventAdapter {    

    @Override
    public boolean fetch( IDataSetInstance dataSet, IUpdatableDataSetRow row ) throws ScriptException {
    }

    @Override
    public void open(IDataSetInstance dataSet) {
    }
}

I generate the report using the following code:

public File actionPdf() throws EngineException, IOException {
    IReportEngine engine = getEngine();

    IReportRunnable design = engine.openReportDesign("c:\\...\\scripted.rptdesign");

    IRunAndRenderTask task = engine.createRunAndRenderTask(design);

    //      Set parent classloader for engine
    task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, ReportingService.class.getClassLoader());      

    File f = new File(System.nanoTime() + "res.pdf");
    final IRenderOption options = new RenderOption();
    options.setOutputFormat("pdf");    
    OutputStream os = new FileOutputStream(f);
    options.setOutputStream(os);
    task.setRenderOption(options);
    task.run();
    task.close();
    os.close();
    return f;
}

However Birt can't find the class:

Caused by: java.lang.ClassNotFoundException: com.foo.aip.ejb.reporting.action.ActionsPerDateDataSet
    at org.eclipse.birt.core.framework.URLClassLoader.findClass1(URLClassLoader.java:188)
    at org.eclipse.birt.core.framework.URLClassLoader$1.run(URLClassLoader.java:156)
    at org.eclipse.birt.core.framework.URLClassLoader$1.run(URLClassLoader.java:1)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.birt.core.framework.URLClassLoader.findClass(URLClassLoader.java:151)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.eclipse.birt.report.engine.executor.ApplicationClassLoader.loadClass(ApplicationClassLoader.java:79)
    at org.eclipse.birt.report.engine.executor.EventHandlerManager.loadClass(EventHandlerManager.java:99)
    ... 85 more

I am out of ideas :( Do you have any hints for me?

The classloader should be set when the engine is initialized, use an object of type org.eclipse.birt.report.engine.api.EngineConfig

EngineConfig config = new EngineConfig();
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,ReportingService.class.getClassLoader()); 

Of course this will work only if "ReportingService" class is in the same classloader than "ActionsPerDateDataSet" but you don't provide informations about that. If it is not the case, set a further classloader to the BIRT engine with

config.setProperty( EngineConstants.WEBAPP_CLASSPATH_KEY,"c:/your-jar-location/actionperdataset.jar;c:/your-class-location" );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM