我的目录结构是这样的:
> makefile
> app.jar
> src
> Main.java
> Main.class
> some other classes
> manifest.txt
我使用以下命令从 makefile 编译:
javac src/*.java
jar cvfm app.jar src/manifest.txt src/*.class
manifest.txt
包含这个:
Main-Class: Main
当我java -jar app.jar
从顶层目录运行时,出现此错误:
$ java -jar app.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Main
Caused by: java.lang.ClassNotFoundException: Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Main. Program will exit.
我尝试将清单更改为说Main-Class: src.Main
,但这也不起作用。这可能很简单,但我发现 Google 没有提供任何简单的解决方案。