I'm trying to trigger main class from a jar file. this is the command I'm using:
java -cp Myjar.jar com.example.MainClass
and I'm getting below error:
could not find or load main class com.example.MainClass
Points to Poinder:
This is a fat jar
I don't have any main class defined in manifest which I think should be fine. (correct me if I'm wrong) So my manifest looks like:
Manifest 1.0
I'm using the correct path.
I tried to remove the contents of psvm and tried to run with sysout but still it gives same error.
Anaylsis: I could see, anonymous class generated with my main class. So when I grep MainClass in jar file, it gives output as
path_to_file/MainClass
path_to_file/MainClass$1
I also tried to create a jar using intellij i.e. using
project structure -> artifacts -> create jar
then build | build artifacts | build
. That also didn't seem to work.
My understanding: Java is able to find the class but seems there is issue with loading it. But I'm unable to figure out why is it unable to load the class. I tried to create a different project's jar and run with same java, it works fine. So there doesn't seem to be issue with java.
Please help me with this, I've tried to search the internet for 2 days now and couldn't find anything helpful. Any help would be highly appreciated.