将jasper导出为pdf时,NoClassDefFoundError:com / itextpdf / text / DocumentException

我创建了一个jasper报告,现在我需要将该报告导出为pdf格式。 这是我的代码。

  // compiles jrxml JasperCompileManager.compileReportToFile(reportName + ".jrxml"); // fills compiled report with parameters and a connection JasperPrint print = JasperFillManager.fillReport(reportName + ".jasper", parameters, connection); // to view the report //JasperViewer.viewReport(print, false); // export repor to pdf JasperExportManager.exportReportToPdfFile(print, "fromXml.pdf"); 

当我使用JasperViewer查看报告时,它工作正常。 但是当我将报告导出为pdf格式时,它给出了以下exception。

 Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException 

但我已将iText jar放入我的库中。

在此处输入图像描述

但有一点,我之前有另一个版本的iText jar。 它给了我同样的例外。 我认为它的版本可能存在一些问题。(我遵循了一个教程,所以我添加了与他们在教程中使用的相同的jar替换我使用过的新jar)。

但问题仍然存在。 我认为这可能是现在的问题(问题的公认答案)。 但我不知道如何解决它。 我删除了整个库,并使用本教程使用的iText jar再次添加它。 但我没有运气。

你能帮我解决这个问题吗? 谢谢!

您需要将iText-2.1.7.jar文件升级到最新版本,因为之前jar使用的包是com.lowagie...

请参阅此处的更改列表,其中显示已更改包名称。