Structuring Your Projects


Standard IDE projects are essentially modular. If your application needs to be built into just one JAR file, you can build it with a single project. If your application exceeds that scope, you can build your application from multiple IDE projects that are linked together with one of those projects declared as the main project.

Setting the Main Project

The main project is the one that project-specific commands (such as Build Main Project) in the main menu always act on. When an application is composed of many related projects, the main project serves as the entry point for the application for purposes of compiling, running, testing, and debugging. You can have only one main project set at a time.

To make a project the main project, right-click that project's node and choose Set Main Project.

If you find that your main project inadvertently gets changed from time to time, it might be because some project templates contain an option to make the new project the main project. If you create a new project that you do not want to be a main project, make sure to deselect the Set As Main Project checkbox in the New Project wizard.


Creating Subprojects

For more complex applications, you might need to create multiple IDE projects, where one project is the application entry point that depends on other projects. (Any project that has another project depending on it functions as a subproject, though it is not specifically labeled as such in the IDE.)

Each IDE project can create one distributable output (such as a JAR file), which in turn might be used by other projects. There is no particular limit to how long a chain of dependencies can be, though the chain must not be circular. (For example, if project A depends on classes in project B, project B cannot depend on classes in project A.)

Although it might be a hassle at first, reorganizing your code to eliminate circular dependencies will probably pay off in the long run by making your code easier to maintain and extend.


To make one project dependent on another project:

  1. Expand the project's node in the Projects window.

  2. Right-click the project's Libraries node and choose Add Project. In the file chooser that appears, navigate to the IDE project folder. All project folders are marked with the icon in the file chooser.

When you add a project to another project's classpath, all sources and Javadoc documentation are recognized by the other project as well.




NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net