Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add other projects as library in netbeans

Tags:

java

netbeans

I have a project A (for example an Ant based Java Application project) and a second project B (a Java Class Library project or another Java Application project, both Ant build based.)

Project B has some additional Java library dependencies (.jar files in the Libraries folder).

A depends on B. A can use classes which are written by myself in B but it can not see classes in the additional libraries of B unless I add those libraries/jar files to A.

Is there a way to get NetBeans to automatically manage the library dependencies in A by including the dependencies of B in addition to B's own jar file? In eclipse when you add .jar files to project B, it is not necessary to add them to A again.

Thanks.

like image 941
Mohammad Reza Kargar Avatar asked Apr 25 '12 12:04

Mohammad Reza Kargar


People also ask

How do I import an external library into NetBeans?

Tools > Libraries > New Library added jna > add jar and added the paths. import com. sun.

How do I import a class from another project in NetBeans?

You have to just make the . jar file of that/those java files which you want to use in another project. right click on file->export->java->. jar then finish.

How do I find Libraries in NetBeans?

Open NetBeans and right-click on the project name in the Projects tab. Select Properties. Select Libraries.


2 Answers

In your project folder you should see a folder called Dependencies, right click on that folder and choose Add Dependency.... Open the Open Projects tab; from there you can select your project from the list. Click Add.

This works for NetBeans IDE 7.2.1.

like image 146
Steve Pitchers Avatar answered Sep 19 '22 11:09

Steve Pitchers


The simpler NetBeans Ant project Libraries folder is used for compile time and run time dependencies of each individual project. If your "Java Class Library" type Ant based project B has additional library dependencies, they are not automatically forwarded or updated in Project A when you include B as a library of A.

When project A is built, it's .jar file will only contain Project A code and the lib/ folder will only include .jar files from it's Libraries folder. This can cause confusion when you upgrade the dependent library versions and possibly forget to upgrade them everywhere you depend on project B.

You will need to manually manage the dependencies unless you switch to a project management and build system that handles this, like Maven.

A NetBeans Maven project will have a Dependencies folder instead of a Libraries folder and if project B is properly setup and registered as a Maven project and project A is also created as a Maven project, you could Add Dependency on B to A and B would forward it's dependency information to Maven project A.

like image 32
jla Avatar answered Sep 18 '22 11:09

jla