Could not find or load main class with a Jar File

后端 未结 16 1200
有刺的猬
有刺的猬 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:26

    At least the way I've done this is as follows:

    If you have a nested src tree (say com.test.myclass.MyClass) and you are compiling from a root directory you need to do the following:

    1) when you create the jar (usually put this in a script): jar -cvfm my.jar com/test/myclass/manifest.txt com/test/myclass/MyClass.class

    2) The manifest should look like:

    Mainfest-version: 1.0 Main-Class: com.test.myclass.MyClass Class-Path: . my.jar

    3) Now you can run the jar from anywhere like this:

    java -jar my.jar

    Hope this helps someone

提交回复
热议问题