NJGUY
NJGUY

Reputation: 2085

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.

Upvotes: 3

Views: 1364

Answers (1)

YYZ
YYZ

Reputation: 779

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

Upvotes: 4

Related Questions