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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28394833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:32:20  来源:igfitidea点击:

NoClassDefFoundError: com/itextpdf/text/DocumentException when exporting jasper to pdf

javajasper-reportsitext

提问by vigamage

I created a jasperreport and now I need to export that report to pdfformat. This is my code for that.

我创建了一个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");

When I view the report using JasperViewer, it works fine. But When I exporting the report into pdfformat, it gives me the following exception.

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

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

But I have put the iText jar into my libraries.

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

enter image description here

在此处输入图片说明

But one thing, I had another version of iTextjar before. It gave me the same exception. I thought that there may be some issues with the version of it.(I followed a tutorial, so I added the same jar as they had used in the tutorial replacing the new jar I had used).

但有一件事,我之前有另一个版本的iTextjar。它给了我同样的例外。我认为它的版本可能存在一些问题。(我遵循了教程,因此我添加了与教程中使用的相同的 jar,替换了我使用的新 jar)。

but still the problem remains. I thought thismay be the issue now(the accepted answer of the question). But I do not know how to fix it. I removed the entire library and added it again with iTextjar which had been used by the tutorial. But I had no luck.

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

Could you please help me to overcome this issue. Thank you!

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

回答by SMA

You need to upgrade your iText-2.1.7.jar file to latest version as earlier the package that was used by jar is com.lowagie...

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

See the change list herewhich says it has changed the package name.

请参阅此处的更改列表其中说明已更改包名称。