我使用 IntelliJ 构建了一个 jar,正确设置了主类。
当我从命令行(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
jar 包含带有 .class 文件的适当目录结构。