简体   繁体   English

没有数据库的简单Jasper报告

[英]Simple Jasper report without a database

I'm totally new in jasperforge || 我完全是jasperforge的新手|| jasperreports and I wish to generate a simple pdf report using only an ireport empty template and no database connections . jasperreports和我希望仅使用ireport空模板而不使用数据库连接来生成简单的pdf报告。

I tried to adapt some simple program to just export the PDF without no data and tried the following code: 我试图改编一些简单的程序以仅导出没有数据的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();
    }
}

,...but it didn't work. ,...但是没有用。 I needed to add the following libraries to the project: 我需要将以下库添加到项目中:

  • commons-logging 公共记录
  • commons-digester 下议院
  • commons-collections 公地收藏

When I tried to run the executable I've got the following error: 当我尝试运行可执行文件时,出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException

I thought that's not related to .jasper file, that was compiled without errors in ireports, but I don't have any clue of whats happening. 我认为这与.jasper文件无关,该文件在ireports中编译时没有错误,但是我不知道发生了什么。

Jasper doesn't depend on groovy unless report language is "groovy". 除非报表语言是“ groovy”,否则Jasper并不依赖于Groovy。 Reports compiled in iReport for some reason have groovy by default. 由于某种原因,在iReport中编译的报表默认情况下具有常规功能。 To change it please right click on report root, Properties, set language to Java and recompile. 要更改它,请右键单击报表根目录“属性”,将语言设置为Java并重新编译。

Try adding groovy library. 尝试添加groovy库。 It will fix the problem. 它将解决问题。 http://groovy.codehaus.org/Download http://groovy.codehaus.org/下载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM