我使用IntelliJ構建了一個jar,正確設置了主類。NoClassDef運行罐子時發現
當我從命令行(Windows)運行「java -jar foo.jar」時,出現聲稱主文件丟失的異常。主類看起來類似:
package mypackage;
public class LockUtil {
public static void main(String[] args) {
...
,我發現了以下異常:
Exception in thread "main" java.lang.NoClassDefFoundError: mypackage/LockUtil
Caused by: java.lang.ClassNotFoundException: mypackage.LockUtil
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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: mypackage.LockUtil. Program will exit.
清單文件包含:
Manifest-Version: 1.0
Created-By: IntelliJ IDEA
Main-Class: mypackage.LockUtil
而且罐子包含適當的目錄結構.class文件。
對不起,這是一個錯誤張貼 - 實際包名是正確的,但...(我更新了問題) – ripper234 2009-07-02 15:11:55