Could not find or load main class with a Jar File

后端 未结 16 1182
有刺的猬
有刺的猬 2020-12-01 09:09

I\'m trying to load a jar using

@echo off
java -jar Test.jar
pause

With the manifest of

Manifest-Version: 1.0
Main-Class:          


        
16条回答
  •  北海茫月
    2020-12-01 09:44

    I got it working like this:

    TestClass.Java

    package classes;
    
    public class TestClass {
    
        public static void main(String[] args) {
            System.out.println("Test");
        }
    
    }
    

    Use javac on the command line to produce TestClass.class. Put TestClass.class in a folder classes/.

    MANIFEST.MF

    Manifest-Version: 1.0
    Main-Class: classes.TestClass
    

    Then run

    jar cfm test.jar MANIFEST.MF classes/
    

    Then run it as

    java -jar test.jar
    

提交回复
热议问题