Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a JAR in NetBeans

Tags:

java

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.

like image 459
Pam Avatar asked Feb 02 '11 21:02

Pam


People also ask

How do I add a jar file to NetBeans 12?

In the project properties window, click on the Libraries node at the left Categories pane. Then on the right side, click on the Run tab and then click on the Add JAR/Folder button and browse the external JAR files you want to add, as shown in the below image. Then click on the OK button.


2 Answers

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

like image 175
Petah Avatar answered Sep 28 '22 02:09

Petah


You want to add libraries to your project and in doing so you have two options as you yourself identified:

Compile-time libraries are libraries which is needed to compile your application. They are not included when your application is assembled (e.g., into a war-file). Libraries of this kind must be provided by the container running your project.

This is useful in situation when you want to vary API and implementation, or when the library is supplied by the container (which is typically the case with javax.servlet which is required to compile but provided by the application server, e.g., Apache Tomcat).

Run-time libraries are libraries which is needed both for compilation and when running your project. This is probably what you want in most cases. If for instance your project is packaged into a war/ear, then these libraries will be included in the package.

As for the other alernatives you have either global libraries using Library Manageror jdk libraries. The latter is simply your regular java libraries, while the former is just a way for your to store a set of libraries under a common name. For all your future projects, instead of manually assigning the libraries you can simply select to import them from your Library Manager.

like image 29
Johan Sjöberg Avatar answered Sep 28 '22 02:09

Johan Sjöberg