Eclipse Birt ClassNotFoundException 异常

Eclipse Birt ClassNotFoundException

我在 Birt (4.4.0) 中创建了脚本数据集以及事件处理程序:

public class ActionsPerDateDataSet extends ScriptedDataSetEventAdapter {    

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

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

我使用以下代码生成报告:

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

但是 Birt 找不到 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.run(URLClassLoader.java:156)
    at org.eclipse.birt.core.framework.URLClassLoader.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

我没主意:( 你对我有什么提示吗?

class加载器应该在引擎初始化时设置,使用org.eclipse.birt.report.engine.api.EngineConfig

类型的对象
EngineConfig config = new EngineConfig();
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,ReportingService.class.getClassLoader()); 

当然,这只有在 "ReportingService" class 与 "ActionsPerDateDataSet" 在同一个 classloader 中时才有效,但您没有提供相关信息。如果不是这种情况,请使用

为 BIRT 引擎设置另一个 classloader
config.setProperty( EngineConstants.WEBAPP_CLASSPATH_KEY,"c:/your-jar-location/actionperdataset.jar;c:/your-class-location" );