Java: 我的 .jar 文件创建了,但是找不到主要的 class?

Java: my .jar file created, but the main class cannot be found?

我有以下步骤:

(1) 我在 /home/a

的 Linux 主目录下

(2) 一个简单的 java 文件,cat m.java

 package my;
 public class m{
     public static void main(String[] args){
     }
 }

(3) javac m.java

(4) mkdir 我的 && cp m.class 我的/

(5) $猫manifest.mf

Manifest-Version: 1.0
Main-Class: my/m
Class-Path: /home/a

(6) jar cfm m.jar manifest.mf m.class

(7) java -jar m.jar

Error: Could not find or load main class m.class

如何让它发挥作用?

Main-Class 应该是用点分隔的包而不是 /

Main-Class: my.m

Main-Class: MyPackage.MyClass

如果不需要更多罐子,请删除 Class-Path

Adding Classes to the JAR File's Classpath You may need to reference classes in other JAR files from within a JAR file.

您需要创建 manifest.txt 文件,将 class 包名称命名为,

Main-Class: MyPackage.MyClass