简体   繁体   中英

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?

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.

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

Main-Class: MyPackage.MyClass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM