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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22513697/
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-08-13 16:12:05  来源:igfitidea点击:

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

javaexceptiontimestampitextbouncycastle

提问by user3412670

I use iText 5.5.0and BouncyCastle bcprov-jdk15on-1.50for digitally signing a pdf. It all works fine if I do not include a time stamp in the MakeSignature.signDetachedmethod.

我使用 iText5.5.0和 BouncyCastlebcprov-jdk15on-1.50对 pdf 进行数字签名。如果我没有在MakeSignature.signDetached方法中包含时间戳,一切都很好。

When I use the TSAClientspecifying the TSAURL, my code gives me the error

当我使用TSAClient指定时TSAURL,我的代码给了我错误

java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable at MakeSignature.signDetached method

and my program gets terminated even though I handled exceptions.

即使我处理了异常,我的程序也会终止。

I tried different versions of bouncycastle jars but I get the same error with difference in the classes not found.

我尝试了不同版本的 bouncycastle jars,但由于找不到类的差异,我得到了相同的错误。

I really need Timestamp included in the Signature. What should I do.

我真的需要在签名中包含时间戳。我该怎么办。

回答by Fred

You can check the dependency of itext 5.5 at the following URL.

您可以在以下 URL 中检查 itext 5.5 的依赖项。

http://mvnrepository.com/artifact/com.itextpdf/itextpdf/5.5.0

http://mvnrepository.com/artifact/com.itextpdf/itextpdf/5.5.0

According to this page, corresponding version of bouncycastle for itext 5.5 is 1.49. I read on a page somewhere on internet that bouncycastle is heavily changing and it is often hard to find corresponding version of bouncycastle for a specific version of itext.

根据此页面,itext 5.5 对应的 bouncycastle 版本为 1.49。我在互联网上某处的页面上读到 bouncycastle 正在发生重大变化,通常很难找到特定版本的 itext 对应的 bouncycastle 版本。

回答by user3656243

Please download the bcprov-jdk15on-150.jar(for JDK 1.5 - 1.7) file from below given link and add in your project to resolve java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodableexception.

请从下面给定的链接下载bcprov-jdk15on-150.jar(适用于 JDK 1.5 - 1.7)文件并添加到您的项目中以解决java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable异常。

http://www.bouncycastle.org/latest_releases.html

http://www.bouncycastle.org/latest_releases.html

find the appropriate jar file from the above link according to your JDK version.

根据您的 JDK 版本从上面的链接中找到合适的 jar 文件。

回答by Amedee Van Gasse

The recommended way of including iText in your project, is to use Maven. Maven will then solve the dependencies for you. I read that you use Eclipse, Eclipse has a very good Maven plugin.

在您的项目中包含 iText 的推荐方法是使用 Maven。然后 Maven 将为您解决依赖项。我读到你使用 Eclipse,Eclipse 有一个非常好的 Maven 插件。

Put this in your pom.xml:

把它放在你的pom.xml

<dependency>
  <groupId>com.itextpdf</groupId>
  <artifactId>itextpdf</artifactId>
  <version>5.5.8</version>
</dependency> 

More info available at http://developers.itextpdf.com/itext-java

更多信息请访问http://developers.itextpdf.com/itext-java