我正在研究一个项目,以PDF格式生成Birt报告。该应用程序并不是要成为Web应用程序。我尝试按照此链接上的报告引擎API示例http://wiki.eclipse.org/simple_execute_(birt)_2.1但是我在运行时会出现错误(运行为 -> java应用程序)代码。我的代码如下。
我的代码如下:
package birt.classicmodels.offices;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
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;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
public class ExecuteReport {
public static void main(String[] args) {
ExecuteReport er = new ExecuteReport();
try {
er.executeReport();
} catch(Exception ex) {
System.out.println(ex.toString());
}
}
public void executeReport() throws EngineException {
IReportEngine engine = null;
EngineConfig config = null;
IReportEngineFactory factory = null;
Object factoryObj = null;
try {
config = new EngineConfig();
config.setBIRTHome("C:\birt-runtime-4.6.0-20160607\ReportEngine");
config.setLogConfig("C:\temp\test", Level.FINEST);
Platform.startup(config);
factoryObj = Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
factory = (IReportEngineFactory) factoryObj;
engine = factory.createReportEngine(config);
// Open the report design
IReportRunnable design = null;
String designPath = "C:\birt-runtime-4.6.0-20160607\ReportEngine\samples\hello_world.rptdesign";
design = engine.openReportDesign(designPath);
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
PDFRenderOption PDF_OPTIONS = new PDFRenderOption();
PDF_OPTIONS.setOutputFileName("C:\temp\test.pdf");
PDF_OPTIONS.setOutputFormat("pdf");
task.setRenderOption(PDF_OPTIONS);
task.run();
task.close();
engine.destroy();
} catch(final Exception ex) {
ex.printStackTrace();
} finally {
Platform.shutdown();
}
}
}
设置:
- 我使用完整的Birt Designer下载安装了Birt设计师。
- 我在Birt Runtime文件夹的Libs文件夹下方添加了所有.jars。
- 主要方法不是我添加的示例的一部分,目的是将报告保存到我的文件系统中。
- 我引用的设计模板是Birt Engine随附的设计示例。
问题:
当我运行代码时(作为 -> Java应用程序运行)时,我会收到以下错误:
- 弹出对话框:
Java虚拟机发射器错误:发生了JNI错误,请检查您的安装,然后重试
在"消息"对话框上单击"确定"后,该控制台将带有以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/birt/core/framework/PlatformConfig at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.eclipse.birt.core.framework.PlatformConfig at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source)
我认为您缺少遵循依赖项
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.6.0-20160607</version>
</dependency>