Including external JARs in a JAR using Netbeans

The task of including external JARs when exporting a Java project into a JAR file should have been easy and straight forward. However, Java demands extra effort for doing this and Eclipse IDE does not provide it automatically (maybe there is a plugin for this, which I did not come along).

The solution is simple and it is a standard computer science solution: use another IDE... and the winner is NetBeans! In general, Netbeans (especially version 6.x) is in a way a smarter IDE than Eclipse. I like the interaction with the user and the ease of customization. The developers have made a good job on the HCI part, which is something great for a non commercial platform.

HOW TO INCLUDE JARs while exporting your Java classes in a JAR?

  • Just create a new Java Project with Netbeans.
  • Go to its Properties -> Sources -> Compile tab and add all the JARs that you want to be included.
  • Go to the Compiling options and enable Track Java Dependencies. This may be optional in some cases.
  • At the Run options you have to define a Main class for your program.
  • When you build your project there would be a JAR file in the dist folder which is ready to be used with no ClassNotFound error messages. Netbeans does that by default. Great! Be careful - do not move the file from this directory without the rest of the contents of the folder because the links with the external JAR files will be broken.
  • It is nice that you will not have to care about the Manifest file or to create any Ant scripts.
  •  

nice

This is nice...!

Not works for me - it just

Not works for me - it just added as source but not linked and ClassNotFoundException :((

It does work

bill's picture

I don't know what you are doing wrong! It worked for me lots of times (and it is still working!).

If you write down exactly what you are doing, we may spot the mistake :).

Thanks. I searched over the

Thanks. I searched over the internet and tour explanation points out everything I need. Thanks a lot.

I was searching for this

I was searching for this answer for few months in a row. Netbeans is too complicated for me, but I am a junior java app developer and I really want to work there. Thanks for publishing it here and helping such newbies as me. I have bookmarked your blog and will be waiting for more nice articles from you in the nearest future.

Sincerely,

Travis Gardon

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.