简体   繁体   中英

Java creating runnable .jar

I am trying to export my GUI project as runnable jar file from eclipse. I have selected the main class and created the run configuration. For some reason, when i am trying to start the program by double clicking on it, i got the following error message from JVM Launcher:

" Could not find the main class, the program will exit "

public class Main {


public static void main (String[] args)
{
    JFrame fr = new JFrame();
    fr.setSize(300,300);
    fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fr.setVisible(true);
}}

I created this simple test for the issue, i got the same message. Main is in a source folder "src" in default package. At Run Configurations, i simply selected the project, and i selected this class as main class.

Thanks

Try running jar with java -jar <path-to-jar-file>.jar

If above is working fine then your jar creation do not have any problem and it has created a correct runnable jar. Problem might be with your installation of JDK/JRE.

Make sure your program is using the same JDK/JRE as the one in your system class-path before exporting your jar file.

You might also check your manifest.txt file by comparing the file in the runnable jar with the one in your project (file should end with a new line).

Hope it helps.

Make sure both java are of same version .

  1. On which runnable jar is exported (say java version 1.mnz).
  2. On Environment where you are running jars(java version should be strictle 1.mnz). where target machine having java version

      Try java -jar <path where ever your jar is >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