NoClassDefFoundError

谬误的产生,是因为Java虚拟机在编译时能找到适合的类,而在运行时不能找到适合的类导致的谬误。

起因(局部思考方向):
  • jar包抵触排包的时候不小心排掉了
  • 类抵触,不同的jar包中含有雷同的该类,不晓得调用哪一个了
  • 低版本的jdk运行了高版本编译的class类

java.lang.NoClassDefFoundError: org/apache/zookeeper/server/ZooTrace

at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1155) ~[zookeeper-3.3.1.jar:3.3.1-942149]

Caused by: java.lang.ClassNotFoundException: Illegal access: this web application instance has been stopped already. Could not load [org.apache.zookeeper.server.ZooTrace]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.

明天遇到的这个问题,以上三个方向排查后都不合乎,而后看到了网上有一篇文章说:
==tomcat重启的时候,因为之前的tomcat中的线程还没有齐全敞开,新启动tomcat就会报这个异样。==

学习了!!

Tomcat运行时异样:Illegal access: this web application instance has been stopped already.

再来理解一下 NoClassDefFoundError和ClassNotFoundException区别

  • NoClassDefFoundError 产生在 JVM 运行时,依据提供的类名,在 classpath 中找到对应的类进行加载,然而当它找不到这个类时,就会呈现此谬误;
  • ClassNotFoundException 是在编译的时候,在 classpath 中找不到对应的类,产生的异样。

疑难?

运行之前不都要编译的吗?

编译之前如果没有找到某个类就会报错;

为啥还要等到运行的时候???

jar包援用

eg:A零碎援用了C jar包,当初B零碎要援用A零碎,把A零碎打成jar包,让B零碎援用。

当B零碎引入了 A jar包,但没有胜利援用C jar包,编译的时候,Maven会放过,不会报异样,

再当B零碎运行时,发现找不到某个类,此时,会报 NoClassDefFoundError