How to Create an Executable File in NetBeans

advertisement
How to Create an Executable File in Netbeans
1. Select the “Run” menu, click “Set Main Project” and select your project.
2. Select the “Run” menu and select “Clean and Build Main Project.”
3. Look in the output window to see where the .jar file has been created (presumably in the …\dist
folder) and that there were no errors.
Note: Make sure that all applicable source files are in the same folder as the main project.
If using a separate, precompiled class file make sure that either one of the two items below are done:
1. Put the .class file in the class folder within the project
2. Right mouse click on the project and select “Properties” and then click on “Libraries”
and add the class
To run an application from the command line do the following:
1. Add a command prompt icon to the folder containing the .jar file.
2. Right click the command prompt icon, click Properties, and remove any path information from
the “Start in:” field.
3. Click the command prompt icon to open a command prompt window.
4. Type the following in the window: java -jar "fileName.jar" where “filename” is the name of the
.jar file and must be in quotes. Note the space between “java” and “-jar“ and between “-jar” and
the file name. Alternatively, you can precede the filename with a path but that is generally too
much trouble.
Trouble shooting
If you get an error when trying to execute the .jar file from the command prompt, make sure that the
class containing the main() method has been set as the main class. To do this, try running the program in
NetBeans by selecting the Run Main Project option (on the Run menu). If you get a dialog box asking for
the main class, enter the name of the class containing the main() method. Finally, repeat the steps
above.
Download