在编译当前执行的类时已存在搜索到的类定义,但不再找到该定义.所以我的问题是,一个类为什么能在一段时间内可用,清楚地响应对其静态方法的调用,然后抛出NoClassDefFoundError?解决方案 NoClassDefFoundError不是ClassNotFoundException.它可能在以下情况下发生: 如果Java虚拟机或ClassLoader实例尝试执行以下操作,则抛出该异常 加载类的定义(作为常规方法调用的一部分或 使用新表达式创建新实例的一部分),并且没有 可以找到该类的定义.我的经验表明,如果静态初始化程序块中存在异常,则也可以引发此异常. 为什么由静态字段初始化引起的NoClassDefFoundError失败? The context is this: I have class with all static methods and a static initialize block. This class is part of a web application, which is packed as a war and deployed inside WebSphere 10.There are situations where other classes in the war try to call methods on this class, only to get a NoClassDefFoundError. What I find strange is that, I can see from the logs that the class's methods and such have already been called multiple times, successfully, but all of a sudden, an identical (previously successful) method call will presently generate a NoClassDefFoundError. At this point any future such calls to the class's static methods will generate that error (until the WebSpehere container is restarted or the war is redeployed).What puzzles me is why the class seems to work for a while before throwing the NoClassDefFoundError. The documentation on this exception says:The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.So my question is,how come a class is usable for a while, clearly responding to calls to its static methods and then throw NoClassDefFoundError? 解决方案 NoClassDefFoundError its not ClassNotFoundException. it can occur when: 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.My experience shows that if there an exception in static initializer block, this exception can be thrown too.Why NoClassDefFoundError caused by static field initialization failure? 这篇关于可以在类已加载/使用后引发NoClassDefFoundError吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 16:57
查看更多