我正在尝试从我的源代码创建一个JAR文件,但是当我运行它时,我得到了类找不到异常 - 它找不到主类,即使我在MANIFEST.MF文件中定义它也是如此。你能发现任何错误吗?
我的JAR结构:
META-INF/
META-INF/MANIFEST.MF
main/
main/java/
main/java/ThreadWatcher.java
main/java/WatcherObject.java
main/resources/
main/resources/WatcherObjectType.java
main/resources/TLogger.java
main/resources/DataProvider.java
main/resources/WatcherObjectStatus.java
main/resources/SettingsProvider.java
main / java / WatcherObject.java包含main方法。
我的MANIFEST.MF:
Manifest-Version: 1.0
Created-By: 1.6.0_27 (Sun Microsystems Inc.)
Main-Class: main.java.ThreadWatcher
当我跑步时,我得到:
Exception in thread "main" java.lang.NoClassDefFoundError: main/java/ThreadWatcher
Caused by: java.lang.ClassNotFoundException: main.java.ThreadWatcher
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: main.java.ThreadWatcher. Program will exit.
感谢您的帮助!
答案 0 :(得分:2)
问题很可能是你包含java源文件,而不是编译的类文件。加载类时,JVM默认查找具有该给定名称的类文件并尝试加载它。由于您没有任何类文件,因此无法加载该类。