找不到Java类iText

问题描述 投票:0回答:1

我有以下问题...。通过日食测试我的代码以加密现有的PDF文件,效果很好。

但是,当编译我的代码时,如果我在eclipse之外运行它,则会发生以下错误:

java.lang.NoClassDefFoundError:org / spongycastle / asn1 / ASN1Encodable

我已经将以下库添加到我的项目中:

<classpathentry kind = "lib" path = "lib/bctsp-jdk16-1.46.jar" />
<classpathentry kind = "lib" path = "lib/bcprov-jdk16-1.46.jar" />
<classpathentry kind = "lib" path = "lib/bcmail-jdk16-1.46.jar" />
<classpathentry kind = "lib" path = "lib/itextpdf-5.2.1.jar" />

我的代码:

public void encryptPdf (String src, String dest, String User, String filePath) throws IOException, DocumentException {

    / ** User password. * /
    byte [] USER = User.getBytes ();
    / ** Owner password. * /
    byte [] OWNER = "test" .getBytes ();

    PdfReader reader = new PdfReader (src);
    PdfStamper stamper = new PdfStamper (reader, new FileOutputStream (filePath + dest));
    stamper.setEncryption (USER, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 |
    PdfWriter.DO_NOT_ENCRYPT_METADATA);
    stamper.close ();
    reader.close ();
}

有人曾经历过吗?有什么建议吗?

java pdf itext
1个回答
0
投票

查看错误消息

java.lang.NoClassDefFoundError:org / spongycastle / asn1 / ASN1Encodable

一个人意识到它是指SpongyCastle,而不是BouncyCastle

因此,您在classpathentry元素中指出的5.2.1版本之前的类路径中显然有iText的GAE版本。适用于GAE的iText版本是针对SpongyCastle库(在不同的程序包结构中实质上等于BouncyCastle)编译的,可在android和类似环境中使用。

确实,您同时发表了评论

还有另一个引用的itext库正在产生冲突。我将其删除,并且可以正常工作!

© www.soinside.com 2019 - 2024. All rights reserved.