I'm trying to create a jar file and run it using java -cp main.jar com.test.Foo.Main
but I keep getting:
Error: Could not find or load main class com.test.Foo.Main
Caused by: java.lang.ClassNotFoundException: com.test.Foo.Main
This is my file structure. So I'm thinking the line in my Main.java
should be package com.test.Foo
correct?
I'm compiling my Main.java
with javac Main.java
which outputs a Main.class
file. Afterward, I create a jar file using jar cfm main.jar META-INF/MANIFEST.MF Main.class
and finally while I'm in the same directory as the jar file <root>/src/com/test/Foo/
I run java -cp main.jar com.test.Foo.Main
and that's when I run into the above error. Any idea how I can run this file like this (and yes I need it to run with this command specifically)?
Main.java
package com.test.Foo;
public class Main {
public static void main (String args[]) {
System.out.println("I am com.test.Foo.Main");
}
}
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: com.test.Foo.Main
I tried using some of the options given in this popular SO question and nothing helped.