[英]Throwing java.lang.ClassNotFoundException even if the class exists in jar file
I cannot understand why this error occurs when I am running the jar file: 我无法理解为什么在运行jar文件时会发生此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/mzmine/main/MZ mineModulesList at net.sf.mzmine.main.MZmineCore.main(MZmineCore.java:100) Caused by: java.lang.ClassNotFoundException: net.sf.mzmine.main.MZmineModulesList 线程“主”中的异常java.lang.NoClassDefFoundError:net / sf.mzmine.main.MZmineCore.main(MZmineCore.java:100)上的net / sf / mzmine / main / MZ mineModulesList造成原因:java.lang.ClassNotFoundException: net.sf.mzmine.main.MZmineModulesList
It says that MZmineModulesList
class is not found but it exists in this path. 它说未找到MZmineModulesList
类,但它存在于此路径中。 Maybe I did something wrong when I was writing classes to the jar file? 在将类写入jar文件时,也许做错了什么?
I wanted to add that this appeared after I replaces MZmineModuleList file with updated version. 我想补充一点,这是在我用更新的版本替换MZmineModuleList文件之后出现的。 What I have done: I extracted files from Jar and added my new classes, and also instead of the old MZmineModuleList class I replaced it with new one, where several lines of codes are added. 我做了什么:我从Jar中提取了文件并添加了新类,并且还用旧的MZmineModuleList类代替了新的类,在其中添加了几行代码。 Maybe when I am writing to the jar file using the method of java.util.jar I missed something? 也许当我使用java.util.jar的方法写入jar文件时,我错过了一些东西吗?
如果类的静态代码块中有错误,则可能会发生NoClassDefFoundError
。
The class may be abigious. 上课可能有点矛盾。 If a class can be loaded from more than one classloader this error may be thrown, too. 如果可以从多个类加载器中加载一个类,则也可能引发此错误。
If you are using an IDE or something else to build everything for you, check to make sure that it included all the classes within the jar. 如果您使用的是IDE或其他方式为您构建所有内容,请检查并确保它包含jar中的所有类。 I've seen the Eclipse IDE export jars without all of the class files included. 我已经看到了不包含所有类文件的Eclipse IDE导出jar。 If that is the case, just put the class file in the jar. 如果是这种情况,只需将类文件放入jar中即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.