Could not find or load main class with a Jar File

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

    If you use package names, it won't work with folders containing dots (Error: Could not find or load main class). Even though it compiles and creates the jar file successfully.

    Instead it requires a complete folder hierarchy.

    Fails:

    com.example.mypackage/
        Main.java
    

    Works:

    com/
        example/
            mypackage/
                Main.java
    

    To compile in Linux:

    javac `find com/ -name '*.java'` \ && jar cfe app.jar com.example.mypackage.Main `find com/ -name '*.class'`

提交回复
热议问题