31

How to export java project to JAR with Netbeans ? I cannot find options like in Eclipse.

Damir
  • 48,513
  • 89
  • 234
  • 352
  • 1
    possible dupe: http://stackoverflow.com/questions/602537/producing-executable-jar-in-netbeans – daveb Dec 21 '10 at 10:11

4 Answers4

37

You need to enable the option

Project Properties -> Build -> Packaging -> Build JAR after compiling

(but this is enabled by default)

a_horse_with_no_name
  • 440,273
  • 77
  • 685
  • 758
19

Do you mean compile it to JAR? NetBeans does that automatically, just do "clean and build" and look in the "dist" subdirectory of your project. There will be the JAR with "lib" folder containing the required libraries. These JAR + lib are enough to run the application.

If you disable "Compile on save" in the project properties, then it is no longer necessary to do "clean and build", simply "build" will suffice in most cases. This will save time if you want to change just a bit of the code and rebuild the JAR. However, note that NetBeans sometimes fails to handle dependencies and binary compatibility properly, which will lead to a faulty JAR throwing "no such method" or other obscure exceptions. Therefore, if you made a lot of changes since the last full rebuild and even remotely unsure that it will still work even if some classes aren't recompiled, then you must still do a full "clean and build" in order to get a perfectly working JAR.

Sergei Tachenov
  • 22,431
  • 8
  • 51
  • 68
  • 2
    if you don't have a dist folder, you need to explicitly run 'clean and build' even though you may have already been compiling and running your program. – anon58192932 Oct 30 '14 at 20:08
11

It does this by default, you just need to look into the project's /dist folder.

Jonas Van der Aa
  • 1,392
  • 10
  • 26
5
  1. Right click your project folder.
  2. Select Properties.
  3. Expand Build option.
  4. Select Packaging.
  5. Now Clean and Build your project (Shift +F11).
  6. jar file will be created at your_project_folder\dist folder.
Rupsingh
  • 1,100
  • 1
  • 17
  • 29