简体   繁体   中英

ClassNotFoundException problems with manifest in created JAR

I'm trying to create a JAR file from my sources, but when I run it I get class not found exception - it can't find the main class, even though I defined it in the MANIFEST.MF file. Can you spot any errors please?

My JAR structure:

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 contains the main method.

My MANIFEST.MF:

Manifest-Version: 1.0
Created-By: 1.6.0_27 (Sun Microsystems Inc.)
Main-Class: main.java.ThreadWatcher

When I run it I get:

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.

Thanks for help!

The problem is most likely that you're including java source files, rather than the compiled classfiles. When you load a class, the JVM by default looks for a classfile with that given name and tries to load it. Since you don't have any classfiles, it can't load the class.

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