Export JAR with Netbeans
Asked Answered
L

4

31

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

Lila answered 21/12, 2010 at 10:2 Comment(1)
possible dupe: #603037Classroom
K
38

You need to enable the option

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

(but this is enabled by default)

Kneehole answered 21/12, 2010 at 10:17 Comment(4)
How would I pack all of the required library files into the JAR automatically using Netbeans ?Everetteeverglade
@kevingreen: You would need to overwrite the ant target and do it "manually". There is no automatic feature to build a "fat" jarKneehole
There's an option now in that menu: Copy Dependent Libraries.Tanner
eclipse is much easier than thisStyrene
P
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.

Pressurize answered 21/12, 2010 at 10:13 Comment(1)
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.Selima
R
11

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

Ravenna answered 21/12, 2010 at 10:25 Comment(2)
all I see is build, nbproject, and src for folders under my project's folder.Selima
figured it out: had to explicitly run 'clean and build' firstSelima
D
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.
Devitt answered 22/5, 2015 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.