Java: My .jar file was created, but I can’t find the main class?

Java: My .jar file was created, but I can’t find the main class? … here is a solution to the problem.

Java: My .jar file was created, but I can’t find the main class?

I have the following steps:

(1) I am under my Linux home directory /home/a

(2) A simple Java file, Cat M.java

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

(3) javac m.java

(4) mkdir my && cp m.class my/

(5) $ cat list .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

How to make it work?

Solution

Main-Class should be packages separated by dots, not /

Main-Class: my.m

Main-Class: MyPackage.MyClass

Remove Class-Path If you don’t need more jars, OK

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

Related Problems and Solutions