Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Jar file in Netbeans

Tags:

jar

netbeans

Well I have my source code that i have done using the IDE netbeans. Now I wanted to move this java application to a web application. For that I need to create a jar file from my source code, so that I could invoke it in ma jsp file. I have not been able to find any option in netbeans or any other way to create a .jar file of this source code. Could someone tell me how to do that.

Thanks

like image 521
user1227433 Avatar asked Mar 13 '12 10:03

user1227433


People also ask

What is jar file in NetBeans?

A JAR file containing your project is created inside the PROJECT_HOME/dist folder. If you have specified any libraries for the project (in addition to the JDK), a lib folder is created in the dist folder. The libraries are copied into dist/lib .


2 Answers

Create a Java archive (.jar) file using NetBeans as follows:

  1. Right-click on the Project name
  2. Select Properties
  3. Click Packaging
  4. Check Build JAR after Compiling
  5. Check Compress JAR File
  6. Click OK to accept changes
  7. Right-click on a Project name
  8. Select Build or Clean and Build

Clean and Build will first delete build artifacts (such as .class files), whereas Build will retain any existing .class files, creating new versions necessary. To elucidate, imagine a project with two classes, A and B.

When built the first time, the IDE creates A.class and B.class. Now you delete B.java but don't clear out B.class. Executing Build should leave B.class in the build directory, and bundle it into the JAR. Selecting Clean and Build will delete B.class. Since B.java was deleted, no longer will B.class be bundled.

The JAR file is built. To view it inside NetBeans:

  1. Click the Files tab
  2. Expand Project name >> dist

Ensure files aren't being excluded when building the JAR file.

like image 111
CBC_NS Avatar answered Oct 28 '22 15:10

CBC_NS


Please do right click on the project and go to properties. Then go to Build and Packaging. You can see the JAR file location that is produced by defualt setting of netbean in the dist directory.

like image 41
user2342262 Avatar answered Oct 28 '22 16:10

user2342262