我是jasperforge ||的全新人物jasperreports和我希望仅使用ireport空模板和无数据库连接生成简单的pdf报告。
我尝试使用一些简单的程序来导出PDF而不需要数据,并尝试使用以下代码:
import java.io.File;
import java.util.HashMap;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.util.JRLoader;
public class JasperTest {
public void generateReport() throws ClassNotFoundException, InstantiationException, IllegalAccessException, JRException {
System.out.println("Filling report...");
JasperPrint print = JasperFillManager.fillReport(jasper_filename, hm);
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, pdf_filename);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.exportReport();
System.out.println("Created file: " + pdf_filename);
System.out.println("Done!");
}
String jasper_filename = "/blue_template.jasper";
String pdf_filename = "/pdf_out.pdf";
HashMap hm = new HashMap();
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, JRException {
System.out.println("Hello World!");
new JasperTest().generateReport();
}
}
,...但它没有用。我需要将以下库添加到项目中:
当我尝试运行可执行文件时,我遇到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
我认为这与.jasper文件无关,它在ireports中编译时没有错误,但我没有任何关于发生什么事情的线索。
答案 0 :(得分:0)
尝试添加groovy库。它将解决问题。 http://groovy.codehaus.org/Download
答案 1 :(得分:0)