JasperReports:NoClassDefFoundError Digester

时间:2012-05-23 08:52:55

标签: jasper-reports

这是我的JasperReports程序,我可以创建一个POJO类,一个数据源类和一个主类。我的代码就像这样

Pojo课程:

private Integer fire;
private Integer width;
private Integer height;
private String stud;
private Integer sound;

public Integer getFire() {
    return fire;
}

public void setFire(Integer fire) {
    this.fire = fire;
}

public Integer getWidth() {
    return width;
}

public void setWidth(Integer width) {
    this.width = width;
}

public Integer getHeight() {
    return height;
}

public void setHeight(Integer height) {
    this.height = height;
}

public String getStud() {
    return stud;
}

public void setStud(String stud) {
    this.stud = stud;
}

public Integer getSound() {
    return sound;
}

public void setSound(Integer sound) {
    this.sound = sound;
}

数据源类:

public class DataBeanMaker {

    public ArrayList<DataBean> getDataBeanList() {
        ArrayList<DataBean> dataBeanList = new ArrayList<DataBean>();

        dataBeanList.add(produce("a", 70, 80, 42, 600));
        dataBeanList.add(produce("UK", 60, 90, 40, 400));
        dataBeanList.add(produce("C", 50, 100, 35, 300));
        dataBeanList.add(produce("CT", 142, 120, 45, 600));

        return dataBeanList;
    }

    private DataBean produce(String stud, Integer fire, Integer height,
            Integer sound, Integer width) {
        DataBean dataBean = new DataBean();

        dataBean.setFire(fire);
        dataBean.setHeight(height);
        dataBean.setSound(sound);
        dataBean.setStud(stud);
        dataBean.setWidth(width);

        return dataBean;
    }
}

主要课程:

public class Reports {

    public static void main(String[] args) {

        try {
            InputStream inputStream = new FileInputStream(
                    "/home/webwerks/test_jasper1.jrxml");
            DataBeanMaker dataBeanMaker = new DataBeanMaker();
            ArrayList<DataBean> dataBeanList = dataBeanMaker.getDataBeanList();
            JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(
                    dataBeanList);
            Map<String, Object> parameters = new HashMap<String, Object>();
            JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            JasperPrint jasperPrint = JasperFillManager.fillReport(
                    jasperReport, parameters, beanColDataSource);
            JasperExportManager.exportReportToPdfFile(jasperPrint,
                    "/home/webwerks/test_jasper.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我可以使用 iReport 工具创建test_jasper.jrxml文件,我可以添加所有jar文件 还有 jasperreport-1.2.7.jar commons-digester-1.7.jar 文件,但我得到以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
    at com.jasper.Reports.main(Reports.java:32)

我是JasperReports的新手,请帮助。

0 个答案:

没有答案