26 ott 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
gennaio 19th, 2009 at 10:21:41permalink
Really?
I’m very glad you found it useful! 🙂
MDT
gennaio 19th, 2009 at 18:46:50permalink
thanks a lot for this content
Dhanishtha
gennaio 23rd, 2009 at 06:56:34permalink
You’re welcome! ^^
MDT
gennaio 23rd, 2009 at 12:36:13permalink
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
febbraio 20th, 2009 at 11:30:18permalink
Doesn’t make sense, are you sure?
Don’t you have something like this?
http://blogs.sun.com/jmxnetbeans/resource/netbeans_properties.jpg
MDT
febbraio 20th, 2009 at 18:52:17permalink
Thanks very very much……..
This is really useful 4 me….
Thanks again!
dharshana
giugno 2nd, 2009 at 17:51:23permalink
You’re very welcome! 🙂
MDT
giugno 2nd, 2009 at 19:10:55permalink
It’s an useful information, many thanks.
ptk
luglio 4th, 2009 at 06:37:41permalink
You’re welcome! 🙂
MDT
luglio 4th, 2009 at 09:12:29permalink
hi…im using netbean 6.8.
after i finish all 7 steps i couldn’t run it in my mobile phone…
is there any extra things i need to do so that i can run it in mobile phone?
doris
gennaio 26th, 2010 at 13:22:14permalink
I don’t know, unfortunately I’m not a mobile-software developer…
MDT
gennaio 27th, 2010 at 02:54:01permalink
^^ thank you…
doris
gennaio 27th, 2010 at 03:18:29permalink
You’re welcome.
Good luck!
MDT
gennaio 27th, 2010 at 03:19:10permalink
I tried to create jar using above steps.
n when I run jar using given command i get error as
“Failed to load Main-Class manifest attribute from myJar.jar”
I have added Main-Class attribute in Manifest.mf but still same error..
Contents of Manifest are
———————————–
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.6.0-b105 (Sun Microsystems Inc.)
Main-Class: ppb.MainClass
——————————————–
Can u help me??
PPB
febbraio 27th, 2010 at 09:39:35permalink
I think you need to modify the Mainifest so that it specifies Main-Class, see also
http://java.sun.com/docs/books/tutorial/jar/basics/run.html
Did you use Netbeans?
MDT
febbraio 27th, 2010 at 13:37:20permalink
Awesome.. Thank you for ending my search.. ♥
sitti
maggio 10th, 2010 at 03:24:32permalink
You’re welcome! 😉
MDT
maggio 10th, 2010 at 11:35:50permalink
can any one set image on where to click the this mentioned up there..
Thanks…
Jay
luglio 11th, 2010 at 16:27:17permalink
What do you mean?
MDT
luglio 11th, 2010 at 16:47:45permalink
I tried as it says but for some reason the jar does not run at all please help.
kam
settembre 7th, 2010 at 17:06:21permalink
If you have more information would be helpful.
What does not work exactly?
MDT
settembre 7th, 2010 at 23:54:26permalink
Well the jar does not run and my program does not begin i really do not understand because i used to make jars but it does not execute.
Thanks
kam
settembre 8th, 2010 at 13:25:03permalink
Uhm, I don’t know…
Maybe try the jar on a different PC and check if it’s working there?
MDT
settembre 8th, 2010 at 23:28:21permalink
will do
thanks
kam
settembre 9th, 2010 at 15:29:26permalink
Thanks a lot, very usefull, I got my .jars running. Greetings from Spain.
iplazlac
gennaio 29th, 2011 at 18:10:05permalink
No problems, you’re welcome!
MDT
gennaio 31st, 2011 at 11:15:46permalink
Thanks a Lot for your information but after creating jar file I got error “failed to load Main-class manifest attribute form” plz tell any solution about this problem………
POOJA
maggio 8th, 2011 at 02:50:24permalink
Thanks alot. Very useful. Please tell me if there is a way i can run the jar file without using cmd line interface
Poonam
maggio 27th, 2011 at 15:19:24permalink
grt…it works…..
235ster
maggio 31st, 2011 at 21:08:28permalink
@Pooja: please try again, there is a problem with your Main Class.
@Poonam: I don’t know, I think that in Windows you can install some sort of JAR plugin that allows you to double-click on jar and run them immediately. Let me know!
MDT
luglio 24th, 2011 at 13:48:04permalink
thanks for this content yar
sudhar
agosto 16th, 2011 at 06:02:55permalink
how we make jar file in netbeans
ankur
settembre 21st, 2011 at 16:41:30permalink
Fantastic Content. Very Clear !!!!!!!!!!!!..
This Executable jar not work in out of this dist folder.
help me for this….
Dhileepan Chakravarthy
marzo 28th, 2013 at 08:18:04permalink