This tutorial explains how to export jar files for Java modules and projects.

Some projects such as Desktop apps or modules need to package the compiled version as a JAR file and run the jar To make a jar file in Netbeans First, Java files are compiled to class files using the Java compiler, Next package class files as Java archive format(JAR) file

How to Export Jar file in Netbeans

To export the jar file, Please follow the below steps.

  • Open Java project in Netbeans Editor
  • Right-click on the Java project, Select Properties
  • It opens the Project Properties window
  • Select Expand on the left side
  • Select Packaging
  • Check the Build JAR after Compiling and Compress JAR File options
  • Save the changes by clicking OK
  • Run the project by right click on the project
  • Select Build or Clean and build options
    • Clean and build: removed all compiled files and do a fresh build
    • Build option does compilation of modified files
  • It creates a jar file in the project/dist folder

How to run a jar file in Netbeans

Usually, from the command line, we can run using the below command.

java -jar <jarfile>

To run the jar file in Netbeans, Please follow the below steps.

  • Open Java project in Netbeans Editor
  • Right-click on the Java project, Select Properties
  • It opens the Project Properties window
  • Select Run on the left side
  • Enter the following values on the Right side
    • Main Class: Entry class to execute
  • Save the changes
  • Run the project by right click on the project
  • Select Build or Clean and build options
    • Clean and build: removed all compiled files and do a fresh build
    • Build option does compilation of modified files
  • It executes a jar file located in the project/dist folder