简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM