javadynamic-reports

Dynamic Reports - ".toPdf(<<filepath>>)" function is not working in Java


I am using Java 8 and Dynamic reports version is 6.0.0. In pom.xml, I have added this dependency :

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

This code is to generate the report parameters:

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));

Here, the variable subreport1 contains all the report data. They are verified to be correct.

After generating all the report data, this is the code I execute to write the report details into a file:

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

At this line where .toPdf is present, the following exception is being thrown:

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)

Please let me know the solution for this error.


Solution

  • I found the actual solution. There was a version mismatch between xerces jar and dynamic reports jar. It was resolved by adding the following dependency :

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