While it's possible that this is due to a classpath mismatch between compile-time and run-time, it's not necessarily true.
(尽管这可能是由于编译时和运行时之间的类路径不匹配导致的,但不一定是正确的。)
It is important to keep two or three different exceptions straight in our head in this case:
(在这种情况下,请务必牢记两个或三个不同的异常:)
java.lang.ClassNotFoundException
This exception indicates that the class was not found on the classpath.
(java.lang.ClassNotFoundException
此异常表明在类路径上找不到该类。)
This indicates that we were trying to load the class definition, and the class did not exist on the classpath. (这表明我们正在尝试加载类定义,并且该类在类路径中不存在。)
java.lang.NoClassDefFoundError
This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it.
(java.lang.NoClassDefFoundError
此异常表明JVM在其内部类定义数据结构中查找了类的定义,但未找到。)
This is different than saying that it could not be loaded from the classpath. (这与说无法从类路径中加载不同。)
Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again). (通常,这表明我们以前曾尝试从类路径中加载类,但由于某种原因而失败-现在我们正尝试再次使用该类(因此,由于上次失败,因此需要对其进行加载),但是我们甚至不打算尝试加载它,因为我们无法提前加载它(并且合理地怀疑我们会再次失败)。)
The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. (较早的故障可能是ClassNotFoundException或ExceptionInInitializerError(指示静态初始化块中的故障)或许多其他问题。)
The point is, a NoClassDefFoundError is not necessarily a classpath problem. (关键是,NoClassDefFoundError不一定是类路径问题。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…