[java] How to add a JAR in NetBeans

Let's say you create a new project, and want it to make use of some 3rd party library, say, widget.jar. Where do you add this JAR:

  1. File >> Project Properties >> Libraries >> Compile-Time Libraries; or
  2. File >> Project Properties >> Libraries >> Run-Time Libraries; or
  3. Tools >> Libraries (Library Manager) >> Library Classpath; or
  4. Tools >> Java Platforms (Java Platform Manager)

All of these dialogs seem to do the same thing but I'm sure they all have their proper usages. Can't find a good "best practices" article online and the NetBeans Help Contents dialog isn't helping with this either.

This question is related to java netbeans

The answer is


If your project's source code has import statements that reference classes that are in widget.jar, you should add the jar to your projects Compile-time Libraries. (The jar widget.jar will automatically be added to your project's Run-time Libraries). That corresponds to (1).

If your source code has imports for classes in some other jar and the source code for those classes has import statements that reference classes in widget.jar, you should add widget.jar to the Run-time libraries list. That corresponds to (2).

You can add the jars directly to the Libraries list in the project properties. You can also create a Library that contains the jar file and then include that Library in the Compile-time or Run-time Libraries list.

If you create a NetBeans Library for widget.jar, you can also associate source code for the jar's content and Javadoc for the APIs defined in widget.jar. This additional information about widget.jar will be used by NetBeans as you debug code. It will also be used to provide addition information when you use code completion in the editor.

You should avoid using Tools >> Java Platform to add a jar to a project. That dialog allows you to modify the classpath that is used to compile and run all projects that use the Java Platform that you create. That may be useful at times but hides your project's dependency on widget.jar almost completely.


Project Files Services Tabls

go files tabs

drag drop file to libs files hover.

return project tabs and what are you see :)


Right click 'libraries' in the project list, then click add.