Reputation: 219
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.
Upvotes: 12
Views: 16682
Reputation: 7404
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.
Upvotes: 2
Reputation: 7364
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.
Upvotes: 5
Reputation: 2503
If you want to add another project as a library in netbeans right click on the libraries directory and select "Add Project", select the project you want to add. When you do this the jar file(in the dist dir) that has been built for the project you are adding will be selected and then click the "Add Project jar files" and that should add the jar file to your project. Alternatively you could select "Add Jar" instead and add the jar file yourself the way that Ravi described.
Upvotes: 0
Reputation: 1482
In your project folder you see a folder called Libraries
, right click on that folder from there you can select your .jar
file. You need not to add .jar
files repeatedly after adding once to your project. You just need to Clean and Build
your project whenever new files are added to .jar
file.
Upvotes: -1