将jasper导出为pdf时,NoClassDefFoundError:com / itextpdf / text / DocumentException [英] NoClassDefFoundError: com/itextpdf/text/DocumentException when exporting jasper to pdf

查看:2169
本文介绍了将jasper导出为pdf时,NoClassDefFoundError:com / itextpdf / text / DocumentException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a jasper report and now I need to export that report to pdf format. This is my code for that.

        // 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 格式时,它会给我以下异常。

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

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



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

But I have put the iText jar into my libraries.

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

But one thing, I had another version of iText jar 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).

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

but still the problem remains. I thought this may 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 iText jar which had been used by the tutorial. But I had no luck.

请你帮我解决这个问题。
谢谢!

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

推荐答案

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

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

查看更改列表此处表示已更改包名称。

See the change list here which says it has changed the package name.

这篇关于将jasper导出为pdf时,NoClassDefFoundError:com / itextpdf / text / DocumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆