NetBeans Quick Tip #16 - Using Dependent Projects
By Roman Strobl on XI 06, 2005
One NetBeans user asked me recently by e-mail when will NetBeans support dependent projects. So I replied how to define dependencies and asked if he wanted more from this features... and the reply was no, he just didn't know that the feature exists! So here's a tip for people who didn't find it yet, hopefully easily accessible via Google (which puts texts from blogs on top of search results).
Why would you want to use dependent projects? If your project gets big enough it is a good idea to divide it into smaller projects. By dividing them this way your code can be better structured by separating logical parts into individual projects. However if you do this, you need to define in first project how to access classes from the second project.
For Java SE projects this is quite straightforward, go to properties of the main project (right-click on the project and choose properties). Go to the Libraries section and choose Add Project. Now you need to find the project folder on your disk and by selecting it, the project's jar is added to the compile classpath:
If you compile the main project then all dependent projects are checked if they are up-to-date and any updated classes they contain are compiled as well.
There are other advantages of having dependent projects, especially if you work in a team, it's handy to have the projects divided than to work on one big project, because people can work on each of them separately. The only drawback I know of is that speed of compilation is slower if you divide your projects too much and define too many dependencies, then compiling the main project takes longer because NetBeans has to check status of all dependent projects.
Note that for NetBeans plug-in projects the dependence mechanism is quite different - either you depend on one of the NetBeans modules or you define dependence on an external library.