我正在尝试使用 Java 中的 iText 7.1.9 jar 创建 PDF 文件。但我遇到了异常。我有编译 jar、设置类路径和构建路径的所有必要步骤。请帮我解决这个问题。
java.lang.NoClassDefFoundError: com/itextpdf/kernel/pdf/PdfDocument
行pdfdoc = new PdfDocument(new PdfReader(file));
。我的 Vaadin8/Maven 的 POM.xml 如下。在属性标签中:
<itext.version>RELEASE</itext.version>
在依赖项中我添加了以下条目:
<!-- https://mvnrepository.com/artifact/com.itextpdf/itext7-core -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.1.9</version>
<type>pom</type>
</dependency>
我已经使用命令行构建了所有 jar mvn部署:部署文件-Dfile=/barcodes-7.1.9.jar -DgroupId=com.roufid.tutorials -DartifactId=example-app -Dversion=1.0 -Dpackaging=jar -Durl=file:./maven-repository/-DrepositoryId=maven-repository -DupdateReleaseInfo=true
最佳答案
这是因为您的代码依赖于一个类文件,并且该类文件在编译时存在,但在运行时找不到。查找构建时间和运行时类路径中的差异。
关于java - 无法在 Java 中使用 iText 7.1.9 创建 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59931116/