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.

 

 

 

0

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.

0

thanks Andrey, will have a look and let you know.

0

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:

 

Manifest-Version: 1.0
Main-Class: com.marqeta.Main
Class-Path: commons-collections4-4.1.jar lib/

but when I run java Product_Support_Suites.jar in Terminal, I am still getting the same error:

xxx@xx-x-xxx 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 else could be wrong plz.

0

Finally I am able to run the .jar file now, but somehow with a workaround.

below was what I run terminal:

zdu@mq-m-zdu Product_Support_Suites_jar % java -cp Product_Support_Suites.jar xxx.xxxxxxx.Main

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?

 

 

0

请先登录再写评论。