1

I have createad a report in jasper report, when i have wrote the code in servlet to export the report in pdf it is not displaying the report.

JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
//OutputStream ouputStream = response.getOutputStream();
//pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:/reports/payment.pdf");
pdfExporter.exportReport();

Now during debugging when debugger came to at this line JRPdfExporter pdfExporter = new JRPdfExporter(); it simply goes in finally block rather in next line. I am stuck into this any solutions.

and the Exception is:

java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException
java.lang.ClassNotFoundException: com.lowagie.text.DocumentException
Alex K
  • 22,315
  • 19
  • 108
  • 236
JN_newbie
  • 5,492
  • 14
  • 59
  • 97

5 Answers5

1

I think you are not included "iText-2.1.7.js2.jar" file to your classpath. First include mentioned file then it will work fine.

Hope it will help to you.

mahesh
  • 31
  • 5
1

Your code looks fine, and It compiles and runs correctly. I suspect that problem is inside JasperPrint. Make sure you actually complie a JasperPrint from your JRXML file.

If you set an empty JasperPrint into the JRPdfExporter, it will still runs correctly, but will result an empty PDF file.

Hope this help you locate the error.

EDIT :

these Exception messages you provided are indicated that JVM can not locate DocumentException, according to package name, that's a class from iText library, if you have used iText, make sure you have included iText in your classpath.

Rangi Lin
  • 9,303
  • 6
  • 45
  • 71
  • JasperPrint object is returing correctly there is not an issue in JasperPrint because i am also using JRHtmlExporter and it is working fine. But i am facing the issue in this JRPdfExporter. I will have to re-look it again. – JN_newbie Sep 30 '11 at 05:58
  • here is the exception...java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException – JN_newbie Sep 30 '11 at 06:30
  • yeah sorry for late reply i also found the solution by importing iText jar file in class path and it works thanks Rangi. – JN_newbie Sep 30 '11 at 09:02
0

Using maven just put your jasper dependency:

    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>3.7.6</version>
    </dependency>

and he put the dependency

enter image description here

Jonnus
  • 2,988
  • 2
  • 24
  • 33
Anthony Piñero
  • 616
  • 5
  • 10
0

Just include itext-1.2.jar inside your class path.

DON
  • 835
  • 1
  • 8
  • 21
-1

You have to add http://itextpdf.com/ jar file

Juan Rada
  • 3,513
  • 1
  • 26
  • 26