26 Oct 2008
How to create executable jar file with NetBeans IDE
Finally after fruitlessy searching for hours, I found out how to create executable files with NetBeans 6.1:
- Right-click with the mouse on your project: “Set as Main Project”
- Right-click with the mouse on your project: “Properties” then “Run”
- Select your Main Class
- in “Libraries” click on “ADD JAR/Folder” and add your wanted libraries
(ATTENTION! If you add libraries as “Customized libraries” instead of “JAR/Folder” the jar file will not work!) - click “OK”
- from the menu select “Build” then “Clean and Build Main Project” (Maiusc+ F11)
- in the Output window you will see where the jar will be created, generally under “/(build-path)/dist/”
If you have added libraries, these will be in a folder under “/(build-path)/dist/lib”.
Remember to manually add files, in the folder where there is the jar, you maybe used in your project, for example if you read them.
In the same folder of the jar file you will also find a README.TXT, for example:
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar “Testprogram.jar”
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, none of the
classpath elements are copied to the lib folder. In such a case,
you need to copy the classpath elements to the lib folder manually after the build.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.
(Thanks to google and this forum)

Thanks for content. I too searched a lot for atricles related to creating jar files and succeeded after reading this content.
Adit
January 19th, 2009 at %I:%M %ppermalink
Really?
I’m very glad you found it useful!
MDT
January 19th, 2009 at %I:%M %ppermalink
thanks a lot for this content
Dhanishtha
January 23rd, 2009 at %I:%M %ppermalink
You’re welcome! ^^
MDT
January 23rd, 2009 at %I:%M %ppermalink
Step2 : When right click on my project then choose “Properties”.
I only saw “Running” ( not Run)
And haven’t “Librarie” anywhere.
am using :
Product Version: NetBeans IDE 6.5 (Build 200811100001)
Java: 1.6.0_11; Java HotSpot(TM) Client VM 11.0-b16
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
Help me plz !
Thank you very much !
TDT
February 20th, 2009 at %I:%M %ppermalink
Doesn’t make sense, are you sure?
Don’t you have something like this?
http://blogs.sun.com/jmxnetbeans/resource/netbeans_properties.jpg
MDT
February 20th, 2009 at %I:%M %ppermalink
Thanks very very much……..
This is really useful 4 me….
Thanks again!
dharshana
June 2nd, 2009 at %I:%M %ppermalink
You’re very welcome!
MDT
June 2nd, 2009 at %I:%M %ppermalink
It’s an useful information, many thanks.
ptk
July 4th, 2009 at %I:%M %ppermalink
You’re welcome!
MDT
July 4th, 2009 at %I:%M %ppermalink