简体   繁体   中英

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:

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

It says that MZmineModulesList class is not found but it exists in this path. Maybe I did something wrong when I was writing classes to the jar file?

I wanted to add that this appeared after I replaces MZmineModuleList file with updated version. 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. Maybe when I am writing to the jar file using the method of java.util.jar I missed something?

如果类的静态代码块中有错误,则可能会发生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. I've seen the Eclipse IDE export jars without all of the class files included. If that is the case, just put the class file in the jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM