Selva
Selva

Reputation: 1670

dynamic report export pdf class not found exception error

I am trying to implement Dynamic Report in java using the dynamic report open source library.

my pom.xml:

<dependencies>
  <!-- https://mvnrepository.com/artifact/net.sourceforge.dynamicreports/dynamicreports-core -->
<dependency>
    <groupId>net.sourceforge.dynamicreports</groupId>
    <artifactId>dynamicreports-core</artifactId>
    <version>6.1.0</version>
</dependency>

my java code:

 List<Employee> employeeList = new ArrayList<Employee>();
             employeeList.add(new Employee("1", "Selva"));
               report()//create new report design
                 .columns(
                    Columns.column("ID", "id", String.class),
                    Columns.column("Name", "name" , String.class) 
                  ) //adds columns
                 .setDataSource(employeeList)
                 .toPdf(new FileOutputStream(new File("D://selvapdf.pdf"))); //export report to pdf

This code is thorwing this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException
    at net.sf.dynamicreports.jasper.transformation.ExporterTransform.pdf(ExporterTransform.java:440)
    at net.sf.dynamicreports.jasper.transformation.ExporterTransform.transform(ExporterTransform.java:134)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.export(JasperReportBuilder.java:891)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:731)
    at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toPdf(JasperReportBuilder.java:720)
    at com.sample.dynamicreport.App.main(App.java:33)
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.DocumentException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

Why dynamic report module does not have this dependency? Whether I should add or any other new approach is there? Below is the output of dependency:tree

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building dynamicreport 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: http://repo.maven.apache.org/maven2/com/lowagie/itext/2.1.7.js6/itext-2.1.7.js6.pom
[INFO] Downloading: http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/com/lowagie/itext/2.1.7.js6/itext-2.1.7.js6.pom
[INFO] Downloading: http://jaspersoft.jfrog.io/jaspersoft/jr-ce-releases/com/lowagie/itext/2.1.7.js6/itext-2.1.7.js6.pom
[WARNING] The POM for com.google.zxing:core:jar:3.3.3 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.434 s
[INFO] Finished at: 2019-12-26T11:23:22+05:30
[INFO] Final Memory: 11M/155M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project dynamicreport: Could not resolve dependencies for project com.sample:dynamicreport:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at net.sourceforge.dynamicreports:dynamicreports-core:jar:6.1.0 -> net.sf.jasperreports:jasperreports:jar:6.9.0 -> com.lowagie:itext:jar:2.1.7.js6: Failed to read artifact descriptor for com.lowagie:itext:jar:2.1.7.js6: Could not transfer artifact com.lowagie:itext:pom:2.1.7.js6 from/to jaspersoft-third-party (http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/): Access denied to http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/com/lowagie/itext/2.1.7.js6/itext-2.1.7.js6.pom. Error code 407, Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  ) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Any help will be greatly appreciated!!!

Upvotes: 1

Views: 834

Answers (1)

hc_dev
hc_dev

Reputation: 9377

Missing dependency iText ?

Probably you are missing a dependency called iText which is needed for exporting to PDF. Thus the compiler throws a NoClassDefFoundError saying that following class is missing: com.lowagie.text.DocumentException.

Resolution 0:

Either re-import your maven project (mvn clean install) and make sure that dependency iText or at least a class called com.lowagie.text.DocumentException is in the classpath.

Or you could use a newer release from DynamicReport's GitHub repository. This is based on Jasper Reports version 6.5.1, which again uses iText for exporting reports to PDF.

If you search for iText within the dependencies for JasperReports 6.1.0 on Maven, you will find:

<dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>2.1.7.js6</version>
    <scope>compile</scope>
  <!-- lines omitted -->
</dependency>

This dependency should work with your DynamicReports version 6.1.0. So you could add it separately to your POM.

See also: Similar NoClassDefFound-error question


After clarifying and updating the question by listing/resolving the dependencies in your POM via suggested commands:

.. there seems to be following (underlying) root-cause.

Issue seems

When Maven tries to resolve or download the dependency from external repositories, there was this proxy-related access-error (HTTP status 407):

Error code 407, Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )

Seems your are behind a proxy which either prevents accessing the remote POM and/or downloading the JAR dependency. There are 2 possible solutions:

Resolution 1: Setup Maven to work with a proxy

See this question and answers on How to access a Maven Repository from behind a Proxy. This will tell you how to edit your Maven settings.xml for proxy-related configuration, as well as how to setup CNTLM or Wagon HTTP lightweight Maven extension.

Resolution 2: Download & install missing dependency manually

First download the JAR file manually from Jaspersoft's repository (JFrog Artifactory) via their browser page: itext-2.1.7.js6.jar

Then install this 3rd party JAR to your local Maven repo.

Upvotes: 1

Related Questions