$ cat Manifest.txt
Main-Class: org.fenix.llanfair.Llanfair

$ cat org/fenix/llanfair/Llanfair.java | grep main
public static void main(String[] args) {
$ jar cfm Llanfair.jar Manifest.txt org
$ java -jar Llanfair.jar
Error: Could not find or load main class org.fenix.llanfair.Llanfair
$ jar -xf Llanfair.jar
$ cat Llanfair/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.8.0_25 (Oracle Corporation)
Main-Class: org.fenix.llanfair.Llanfair

$ ls Llanfair/org/fenix/llanfair/ | grep Llanfair
Llanfair$1.class
Llanfair$2.class
Llanfair$MenuItem.class
Llanfair$RecentMenuItem.class
Llanfair.class
$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


我希望java -jar Llanfair.jar可以启动我的应用程序,所以我不确定我在做什么错。我正常运行Java代码时,在lib /中确实有几个文件位于我的类路径中,是否需要包括这些文件?

如果重要,我的操作系统是Mac OS 10.11.1。

最佳答案

似乎Llanfair.jar中的文件结构错误。

根据您的评论,jar -xf Llanfair.jar创建一个类似

Llanfair/META-INF/MANIFEST.MF
Llanfair/org/fenix/llanfair/Llanfair.class


但是jar文件中的结构必须是

META-INF/MANIFEST.MF
org/fenix/llanfair/Llanfair.class

09-26 11:25