Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find main class, java error

I have been testing a java swing program that I have been making. On my one computer, the one I originally made it on, it works fine. I have tested the same program on 3 different computers and it runs when I launch it out of the ide, but when I double click the jar I get a popup error window titled 'Java Virtual machien Launcher'. The error is "Could not find the main class: xxxxxxx. Program will exit."

I cannot figure out for the life of me what is going on. It was working before.

like image 477
NJGUY Avatar asked Mar 25 '26 04:03

NJGUY


1 Answers

You need to include a Manifest file within your jar. In this, you specify which class is to be used as the entry point when the jar gets launched.

Create a file called Manifest.txt, and add:

 Main-Class: yourMainClass.class

Then, to create the jar :

jar cfm JarName.jar Manifest.txt yourMainClass/*.class

To run the from the command line, use : java -jar JarName.jar

like image 133
YYZ Avatar answered Mar 27 '26 17:03

YYZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!