How To Create A Java Archive (.jar) File Using NetBeans IDE.
- Right-click on the desired project of which you wish to create an archive file in the projects window.
- Then select Properties option from the list
- You’ll see a Project Properties window in which you need to click on the Packaging option
- Check Build JAR after Compiling
- Check Copy Dependent Libraries
- Click OK to commit all the options
- Once you are done with the above steps Right-click on a Project name again
- 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
- Click the Files tab in the IDE
- 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.