Q: I did the adding functionality tutorial and hit f11 to build the project. I went to the dist folder and double-clicked on the jar file created but it would not run. How do I package the file/s to make it run?

A: There are several possible reasons for your program not to run, it would be best if you used the following command line from your command prompt and posted the output:

 java -jar <jarfile>

A few items to check:

  • Have you defined the main class of your program? When you double-click the jar file, Java will try to fetch the name of the main class from the manifest within the jar and then run that class. If you didn't define the main class upon building the jar, Java has no way to find out which class it should run;
  • Are all the necessary libraries available? If your program needs a library that is not available, you're likely to see a few ClassNotFoundException's;
  • Maybe you compiled your program with a newer JDK than the one you're trying to run it with. For example, you compiled with JDK 1.6, but you're trying to run it with JRE 1.4. In that case, you should recompile your program not to use any language features or classes above JRE 1.4.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo