我是全新的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文件無關,編譯時沒有錯誤n ireports,但我不知道發生了什麼。
您是否嘗試添加groovy庫/類?這不是運行時錯誤,而是在加載使用groovy類的類定義時發生的錯誤。 – ZeissS