Add other projects as a library in netbeans

I have a project A (for example, an Ant-based Java application project) and a second B project (a Java class library project or another Java application project based on the Ant assembly).

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

A depends on B. A can use the classes I wrote in B, but cannot see the classes in the additional libraries of B unless I add these libraries / jar files to A.

Is there a way to get NetBeans to automatically manage library dependencies in A, including B dependencies in addition to B's own JAR file? In eclipse, when you add .jar files to project B, there is no need to add them again to A.

Thank you

+8
source share
4 answers

In the project folder, you will see a folder named Dependencies , right-click on this folder and select Add Dependency... Open the tab Open Projects ; from there you can select your project from the list. Click Add .

This works for NetBeans IDE 7.2.1.

+1
source

If you want to add another project as a library to netbeans, right-click on the library directory and select "Add Project", select the project you want to add. When you do this, the jar file (in the distribution) that was created for the project to be added will be selected, and then click "Add project jar files" and it should add the jar file to your project. Alternatively, you can select "Add Jar" and add the jar file yourself as described by Ravi.

0
source

The simpler Library folder of the Ant NetBeans project is used to determine the compilation time and the execution time of each individual project. If your project B β€œJava Class Library” of type B has additional library dependencies, they will not be automatically forwarded or updated in Project A if you include B as library A.

When you create Project A, its .jar file will contain only the code for Project A, and the lib / folder will contain only .jar files from the Libraries folder. This can be confusing when updating dependent versions of a library, and you may forget to update them wherever you depend on project B.

You will need to manually manage the dependencies unless you switch to a project management system and create a system that does this, for example, Maven.

The NetBeans Maven project will have a Dependencies folder instead of the Libraries folder, and if Project B is correctly configured and registered as a Maven project, and Project A is also created as a Maven project, you can add a Dependency from B to A and B will forward this is dependency information for Maven Project A.

0
source

In the project folder you see a folder called Libraries , right-click on this folder, you can select the .jar file. You do not need to add .jar files again after adding once to your project. You just need to Clean and Build your project when new files are added to the .jar file.

-one
source

All Articles