Netbeans Java: how to add another dependency project as a library?

Suppose there are many simple projects, A, B, C, each of which needs to use the same general project Z. All parts are in the process of development.

So we add project Z as a library to A, B and C.

As an example: Class A has a single method: main (). Class Z is a simple JFrame-based form. Z includes NB IDE default main () to create an instance of the form, so it can be run separately, but in the example use A.main () calls Z.main () to show the form.

This works fine for a simple form in class Z.

However, suppose we add components to the Z class from SwingX or other non-standard libraries. This is an automatic addition of the appropriate library dependencies to the Z project. We can check Z by running Z.main () directly - it works fine. However, if we recompile and run A.main () now, an exception is thrown: the SwingX library (or something else) cannot be found.

This can be made to work by adding the Z dependencies to A. Therefore, the problem is that this mechanism for adding a project as a library does not care about adding the dependencies of this other library / project.

What is the right solution?

Netbeans 7.2 using ANT.

There may be a duplicate of these similar questions that do not have verified answers:

add other projects as a library in netbeans

Netbeans - adding a library that is currently being edited

+4
source share
1 answer

This topic is covered in this NetBeans error report: Error 47507 - [40cat] Transitively needed libraries will not be automatically added to the runtime class path

It's a little unbelievable that this has been in effect for over eight years and is prone to 19 recurring problems. There is a long discussion related to this issue. There is one moderately useful workaround, user "fommil" in 2008-01-10:

โ€œMy workaround is that for each project [library dependent] I define a library in the library manager namedโ€œ library.dep โ€. Here I define class paths, sources, and javadocs for these project dependencies. Then, if another the project ever depends on the "project", I add "project.dep" to its runtime (and testing) dependencies. "

fommil continues to discuss the flaws of this approach, but perhaps this is better than nothing.

In any case, I am going to announce that this question โ€œansweredโ€, even if it is not โ€œresolvedโ€.

+3
source

All Articles