我在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找不到课程:
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
我没有想法:( 你有什么提示吗?
答案 0 :(得分:1)
应该在初始化引擎时设置类加载器,使用org.eclipse.birt.report.engine.api.EngineConfig类型的对象
EngineConfig config = new EngineConfig();
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,ReportingService.class.getClassLoader());
当然,只有当“ReportingService”类与“ActionsPerDateDataSet”位于同一个类加载器中但您没有提供有关该类的信息时,这才有效。如果不是这种情况,请使用
为BIRT引擎设置另一个类加载器config.setProperty( EngineConstants.WEBAPP_CLASSPATH_KEY,"c:/your-jar-location/actionperdataset.jar;c:/your-class-location" );