java 未找到类定义错误:org/弹跳城堡/jce/spec/ECPublicKeySpec,即使弹跳城堡可用

6yoyoihd  于 2023-01-15  发布在  Java
关注(0)|答案(2)|浏览(181)

我运行了一个tomcat8.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-jdk 15 on。我查看了生成的.war文件和包含jar的WEB-INF文件夹。我尝试重新下载maven依赖项,在eclipse中进行了项目清理和maven清理。
我还在www.example.com文件中添加了相应的行java.security:

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

奇怪的是,我可以在某个时候访问ECPublicKeySpec。例如:

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上,它就能工作。如果我把它部署到远程Tomcat上,它就不能工作。
编辑2: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] ------------------------------------------------------------------------
50pmv0ei

50pmv0ei1#

在我的例子中,我在CentOS上运行的远程Tomcat服务器中没有收到任何错误。但是,我在Windows 10上运行的本地环境中收到了NoClassDefFoundError,尽管相关的maven依赖项已经导入。幸运的是,除了maven依赖项,将bcprov-jdk15on-1.55.jar文件复制到本地环境中的**$java_home/jre/lib/ext**解决了这个问题。

5jdjgkvh

5jdjgkvh2#

我认为这是由于您的本地tomcat服务器在保存更改时自动重建/启动。
我得到了同样的问题,但重新启动Tomcat服务器修复了它,但只要我做了任何代码更改并保存,错误就回来了。

相关问题