NoClassDefFoundError:org / bouncycastle / jce / spec / ECPublicKeySpec即使有bouncycastle可用

时间:2017-10-10 10:21:43

标签: java maven tomcat bouncycastle

我运行了一个tomcat 8.5并在其上部署了我的应用程序。 虽然编译一切都很好,但在运行时会发生以下错误:

java.lang.NoClassDefFoundError: org/bouncycastle/jce/spec/ECPublicKeySpec
org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(Unknown Source)
java.security.KeyFactory.generatePublic(KeyFactory.java:334)
COMPANY.server.impl.BouncyCastleCrypto.decodePublicKey(BouncyCastleCrypto.java:87)
COMPANY.server.impl.U2FServerReferenceImpl.processSignResponse(U2FServerReferenceImpl.java:270)
COMPANY.tools.httpserver.servlets.SignFinishServletImpl.doGet(SignFinishServletImpl.java:41)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

这是我得到的所有堆栈跟踪。

我已经尝试了几个版本的bouncycastle依赖(1.58和1.50,我使用maven)bcprov-jdk15on。我查看了生成的.war文件,WEB-INF文件夹包含jar。我尝试重新下载maven依赖项,在Eclipse中完成一个项目清理和maven清理。

我还在java.security文件中添加了相应的行:

security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider

奇怪的是,我可以在某个时候访问ECPublicKeySpec。 E.g:

ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(point,
      new ECParameterSpec(
          curve.getCurve(),
          curve.getG(),
          curve.getN(),
          curve.getH()));
  logger.info(ecPublicKeySpec.toString());

上述工作正常但是:

KeyFactory.getInstance("ECDSA").generatePublic(ecPublicKeySpec);

KeyFactory.getInstance("ECDSA", "BC").generatePublic(ecPublicKeySpec);

这不起作用并产生NoClassDefFoundError。

编辑:忘记提及:如果我将我的应用程序部署到我的tomcat在localhost它可以工作。如果我将它部署到远程tomcat它不起作用。

EDIT2:mvn dependency:tree -Dverbose -Dincludes=org/bouncycastle/jce/spec/ECPublicKeySpec的输出:

[WARNING] 
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'profiles' (position: START_TAG seen ...</profile>\n     <profiles>... @276:16)  @ /Users/tinoa/.m2/settings.xml, line 276, column 16
[WARNING] 
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building application_implemented 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ application_implemented ---
...
lots of "Downloading/Downloaded" lines...
...
Downloaded: 
https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
invoker/2.0.11/maven-invoker-2.0.11.jar (29 kB at 22 kB/s)
Downloaded: 
https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-
util/0.9.0.M2/aether-util-0.9.0.M2.jar (134 kB at 102 kB/s)
Downloaded: https://repo.maven.apache.org/maven2/commons-lang/commons-
lang/2.6/commons-lang-2.6.jar (284 kB at 200 kB/s)
Downloaded: https://repo.maven.apache.org/maven2/commons-
collections/commons-collections/3.2.1/commons-collections-3.2.1.jar 
(575 kB at 333 kB/s)
[INFO] ----------------------------------------------------------------
--------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------------------
--------
[INFO] Total time: 15.216 s
[INFO] Finished at: 2017-10-10T15:05:40+02:00
[INFO] Final Memory: 17M/297M
[INFO] ------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:1)

就我而言,在CentOS上运行的远程tomcat服务器上没有任何错误。但是,尽管已经导入了相关的maven依赖项,但在运行Windows 10的本地环境中却出现了 NoClassDefFoundError 。幸运的是,除了maven依赖之外,还可以在本地环境中将bcprov-jdk15on-1.55.jar文件复制到 $ java_home / jre / lib / ext 来解决该问题。