1

I've seen many similar questions but I've decided to post mine because users that had posted other questions were not in my exact same conditions. I'm trying to learn more the Java cli and right now I'm trying to execute a simple program contained in a JAR created by me. The source code is composed by a single file called Main.java.

Root directory structure:

- src
--- Main.java
- META-INF
--- MANIFEST.mf

Content of Main.java:

package src;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Content of MANIFEST.mf

Manifest-Version: 1.0
Main-Class: src.Main

I've compiled the Main class and stored into a directory named classes. Updated directory structure:

- classes
--- src
------ Main.class
- src
--- Main.java
- META-INF
--- MANIFEST.mf

Then I've created a JAR file named myJarFile.jar into the root folder and the directory structure inside of the JAR file is the following:

- classes
--- src
------ Main.class
- META-INF
--- MANIFEST.mf

Where the content of MANIFEST.mf is the one provided above. Now, from within the root folder, I tried to issue the command java -jar myJarFile.jar but I got the error:

Error: Could not find or load main class src.Main
Caused by: java.lang.ClassNotFoundException: src.Main
GJCode
  • 1,959
  • 3
  • 13
  • 30

0 Answers0