动态报告-“ .toPdf(<< filepath >>)”函数在Java中不起作用

时间:2019-11-26 12:44:26

标签: java dynamic-reports

我正在使用Java 8,动态报表的版本是6.0.0。 在pom.xml中,我添加了此依赖项:

<dependency>
    <groupId>net.sourceforge.dynamicreports</groupId>
    <artifactId>dynamicreports-core</artifactId>
    <version>6.0.0</version>
</dependency>

此代码用于生成报告参数:

JasperReportBuilder report = new JasperReportBuilder();
report.setPageMargin(DynamicReports.margin().setLeft(30).setRight(30).setTop(10).setBottom(10));
report.setPageFormat(PageType.A4, PageOrientation.PORTRAIT);
report.title(cmp.subreport(subReport1));

此处,变量subreport1包含所有报告数据。他们被证明是正确的。

生成所有报告数据后,这是我执行的将报告详细信息写入文件的代码:

FileOutputStream st = new FileOutputStream("<<DUMMY_FILE_PATH>>");
report.toPdf(st);

.toPdf存在的这一行,将引发以下异常:

Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
    at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.<init>(SimpleFontExtensionHelper.java:149)
    at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.getInstance(SimpleFontExtensionHelper.java:131)
    at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.ensureFontExtensions(FontExtensionsRegistry.java:80)
    at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:57)
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:130)
    at net.sf.jasperreports.engine.DefaultJasperReportsContext.getExtensions(DefaultJasperReportsContext.java:277)
    at net.sf.jasperreports.engine.fonts.FontUtil.getFontInfo(FontUtil.java:191)
    at net.sf.jasperreports.engine.fonts.FontUtil.getFontInfo(FontUtil.java:291)
    at net.sf.jasperreports.engine.fonts.FontUtil.getAwtFontFromBundles(FontUtil.java:476)
    at net.sf.jasperreports.engine.fonts.FontUtil.getAwtFontFromBundles(FontUtil.java:466)
    at net.sf.dynamicreports.design.transformation.StyleResolver.getFont(StyleResolver.java:122)
    at net.sf.dynamicreports.design.transformation.StyleResolver.getFont(StyleResolver.java:100)
    at net.sf.dynamicreports.design.transformation.StyleResolver.getFontHeight(StyleResolver.java:69)
    at net.sf.dynamicreports.design.transformation.TemplateTransform.getTextFieldHeight(TemplateTransform.java:1391)
    at net.sf.dynamicreports.design.transformation.ComponentTransform.textField(ComponentTransform.java:395)
    at net.sf.dynamicreports.design.transformation.ComponentTransform.component(ComponentTransform.java:155)
    at net.sf.dynamicreports.design.transformation.ComponentTransform.list(ComponentTransform.java:303)
    at net.sf.dynamicreports.design.transformation.BandTransform.band(BandTransform.java:231)
    at net.sf.dynamicreports.design.transformation.BandTransform.transform(BandTransform.java:86)
    at net.sf.dynamicreports.design.base.DRDesignReport.transform(DRDesignReport.java:155)
    at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:127)
    at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:111)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperReportDesign(JasperReportBuilder.java:299)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.getJasperParameters(JasperReportBuilder.java:346)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:363)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.export(JasperReportBuilder.java:896)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:735)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:724)

请让我知道此错误的解决方案。

1 个答案:

答案 0 :(得分:1)

我找到了实际的解决方案。 xerces jar和动态报告jar之间版本不匹配。通过添加以下依赖关系来解决此问题:

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.11.0</version>
</dependency>