1

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!!!

Selva
  • 1,620
  • 3
  • 33
  • 63
  • I use https://github.com/LibrePDF/OpenPDF its an update for iText. Migrating really legacy(like <2010) was really easy. If u r locked in to "dynamicreports" thenyou will need to try and fix "NoClassDefFoundError". here it is in OpenPdf https://github.com/pretix/OpenPDF/blob/master/openpdf/src/main/java/com/lowagie/text/DocumentException.java – Nigel Savage Dec 23 '19 at 12:44
  • Thanks Nigel, I have to use the dynamic report open source module i hope it internally using itext for that only I am going with itext – Selva Dec 23 '19 at 13:39
  • please upvote @hc_dev ans if it fixes your issue or if hc_dev ans not fix let us know – Nigel Savage Dec 23 '19 at 13:42
  • Hi Madhesh, please [edit] your question and add output of both maven commands (as you already did in comment + as Nigel suggests). We're close to the solution – hc_dev Dec 23 '19 at 19:27
  • @Madhesh Thanks for updating. I found a possible _407/proxy issue_, researched and updated my answer. Please always monitor maven-logging closely, especially when behind a proxy :-( – hc_dev Dec 26 '19 at 23:07
  • @hc_dev, Thanks I will implement the same and update you – Selva Dec 27 '19 at 07:30
  • @hc_dev, thank you so much it solves the problem. – Selva Dec 27 '19 at 07:36

1 Answers1

1

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.

hc_dev
  • 8,389
  • 1
  • 26
  • 38
  • 1
    thanks, I am using the updated dependency from maven. But the dependency does not include itext in it, – Selva Dec 23 '19 at 13:37
  • @Madhesh Did you list dependencies via [mvn dependency:resolve](https://grep.codeconsult.ch/2010/07/08/list-all-your-maven-dependencies/)? If `itext` not listed, try including it separately. – hc_dev Dec 23 '19 at 13:56
  • But include __without __, so it will not only be included at compile time, but also at _runtime_. – hc_dev Dec 23 '19 at 14:03
  • 1
    When I run the command I am getting this error, 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: 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. – Selva Dec 23 '19 at 14:04
  • 1
    would be good value to show the dependecy tree with 'mvn dependency:tree -Dverbose' then update your question with the output so we can see whats actually there – Nigel Savage Dec 23 '19 at 15:58
  • @NigelSavage That will definitely help. Good command to show the root-cause here – hc_dev Dec 23 '19 at 19:23