How to export java project to JAR with Netbeans ? I cannot find options like in Eclipse.
-
1possible dupe: http://stackoverflow.com/questions/602537/producing-executable-jar-in-netbeans – daveb Dec 21 '10 at 10:11
4 Answers
You need to enable the option
Project Properties -> Build -> Packaging -> Build JAR after compiling
(but this is enabled by default)
-
How would I pack all of the required library files into the JAR automatically using Netbeans ? – kevingreen Apr 10 '12 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 – Apr 10 '12 at 17:16
-
-
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.

- 24,345
- 8
- 57
- 73
-
2if 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. – fIwJlxSzApHEZIl Oct 30 '14 at 20:08
It does this by default, you just need to look into the project's /dist
folder.

- 1,441
- 12
- 27
-
all I see is build, nbproject, and src for folders under my project's folder. – fIwJlxSzApHEZIl Oct 30 '14 at 20:04
-
2
- Right click your project folder.
- Select Properties.
- Expand Build option.
- Select Packaging.
- Now Clean and Build your project (Shift +F11).
- jar file will be created at your_project_folder\dist folder.

- 1,128
- 1
- 18
- 34