Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've got these following steps:

(1) I'm under my Linux home directory of /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 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

How to make it work?

like image 580
Troskyvs Avatar asked Mar 13 '26 04:03

Troskyvs


1 Answers

Main-Class should be with package with dot separated and not /

Main-Class: my.m

Main-Class: MyPackage.MyClass

Remove Class-Path line if you don't need more jars

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

like image 113
user7294900 Avatar answered Mar 14 '26 17:03

user7294900



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!