31

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

1

4 Answers 4

38

You need to enable the option

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

(but this is enabled by default)

4
  • How would I pack all of the required library files into the JAR automatically using Netbeans ?
    – kevingreen
    Apr 10, 2012 at 17:06
  • 1
    @kevingreen: You would need to overwrite the ant target and do it "manually". There is no automatic feature to build a "fat" jar
    – user330315
    Apr 10, 2012 at 17:16
  • There's an option now in that menu: Copy Dependent Libraries. Dec 19, 2014 at 13:36
  • eclipse is much easier than this
    – Amol Bais
    Jan 10, 2020 at 8:41
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.

1
  • 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. Oct 30, 2014 at 20:08
11

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

2
  • all I see is build, nbproject, and src for folders under my project's folder. Oct 30, 2014 at 20:04
  • 2
    figured it out: had to explicitly run 'clean and build' first Oct 30, 2014 at 20:10
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.