如何为JDK类/ jar获取NoClassDefFound错误?

huangapple go评论158阅读模式
英文:

How can one get a NoClassDefFound for a JDK class/jar?

问题

在更新依赖项版本时,我开始遇到一个java.lang.NoClassDefFoundError: javax/net/ssl/SSLSession错误。javax.net.ssl.SSLSession是在rt.jar中找到的JDK类。更新依赖项会导致找不到JDK jar文件吗?

编辑:对我来说,答案是这样的,这样的依赖变更不能导致这样的结果。当时并不知道有一个基础镜像变更是导致这个问题的原因。

我会保留这个问题,因为我认为回复和评论对于后来遇到类似问题的人可能会有帮助。对于这样的人,我建议:仔细检查你的类路径,然后再检查一下你的jdk目录。

英文:

In updating a version of a dependency, I began getting a java.lang.NoClassDefFoundError: javax/net/ssl/SSLSession. javax.net.ssl.SSLSession is a JDK class found in rt.jar. How can updating a dependency cause a JDK jar to not be found?

EDIT: the answer for me is that such a dep change can't cause this result. There was a base image change that was not known at the time of asking that was responsible.

I am leaving the question up as I think the replies and comments could be helpful to someone coming here for a similar issue. To such people I recommend: double check you classpath and double check your jdk directory.

答案1

得分: 1

请注意您并非在查看ClassNotFoundException

ApiDoc 关于 NoClassDefFoundError 的说明:
如果 Java 虚拟机或 ClassLoader 实例尝试加载类的定义(作为正常方法调用的一部分或作为使用新表达式创建新实例的一部分)并且找不到类的定义,则会抛出此异常。
在当前执行的类编译时,所搜索的类定义是存在的,但现在无法找到该定义。

英文:

Be aware you are not looking at a ClassNotFoundException.

The ApiDoc states about NoClassDefFoundError:
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

huangapple
  • 本文由 发表于 2023年8月11日 03:49:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定