Error: Could not find or load main class when run .jar in Mac terminal
Hi team,
I have followed this article to successfully built the JAR artifacts:https://www.jetbrains.com/help/idea/compiling-applications.html#package_into_jar , and it runs perfectly fine in IntelliJ IDEA, but when I try to run the JAR artifacts in my Mac terminal with java command, I am getting below error:
Error: Could not find or load main class xxxxx.jar
Caused by: java.lang.ClassNotFoundException: xxxx.jar
user@firm Product_Support_Suites_jar % pwd
/Users/user/Desktop/Product_Support_Suites/out/artifacts/Product_Support_Suites_jar
user@firm Product_Support_Suites_jar % java Product_Support_Suites.jar
Error: Could not find or load main class Product_Support_Suites.jar
Caused by: java.lang.ClassNotFoundException: Product_Support_Suites.jar
what could be the issue please.
Please sign in to leave a comment.
You need to compose the manifest file correctly for the jar and specify the main class in it. Check some tutorials, for example check the Understanding the JAR Manifest File.
thanks Andrey, will have a look and let you know.
this is my MANIFEST.MF file, and it is auto populated when I built Artifacts (.jar) from IntelliJ, and it does have the correct Main-Class, as per below:
but when I run java Product_Support_Suites.jar in Terminal, I am still getting the same error:
what else could be wrong plz.
Finally I am able to run the .jar file now, but somehow with a workaround.
below was what I run terminal:
somehow I have to specify the hierarchy of the entry point from my package, does that mean the MANIFEST.MF file actually didnt take any effect?