Jar file creation in netbeans

How To Create A Java Archive (.jar) File Using NetBeans IDE.

  1. Right-click on the desired project of which you wish to create an archive file in the projects window.
  2. Then select Properties option from the list
  3. You’ll see a Project Properties window in which you need to click on the Packaging option
  4. Check Build JAR after Compiling
  5. Check Copy Dependent Libraries
  6. Click OK to commit all the options
  7. Once you are done with the above steps Right-click on a Project name again
  8. Select the Build or Clean and Build option.What will Clean and Build do??
    It will delete the already build artifacts such as the .Class files, whereas Build will keep any existing .Class files, creating new versions necessary.
    For example, imagine a project with two classes, A and B.
    When you build your project for the first time, the IDE creates the .Class files. Due to some reasons you don’t need B.java file so you delete it but you don’t clear the B.Class file.
    Executing Build will leave B.Class in the build directory, and bundle it into the JAR even when it’s of no use. Selecting Clean and Build option will delete B.Class file Since B.java was  already deleted, and no longer will B.Class be bundled.

The JAR file is has been built successfully.

 

To view the JAR File inside NetBeans

  1. Click the Files tab in the IDE
  2. Expand Project name >> dist
    ( This is where you’ll find the Java Archive File (.JAR) file.)

One can also view it inside the workspace where all your java projects are saved, in the respective dist directories.

Leave a Comment