Introduction to IDE Projects


The starting point for most work in the IDE is through the creation of a project. When you create a project, the IDE typically does the following things for you (depending on project type):

  • Creates a source tree with a skeleton class inside.

  • Creates a folder for unit tests.

  • Sets classpaths for compilation, running, and (depending on type of project) testing. (The compilation classpath also determines the classes that the Source Editor is aware of, for example, when you use code completion features.)

  • Sets the Java platform on which the project will run. By default, it is the same platform that the IDE runs on.

  • Creates an Ant build script (build.xml), which contains the instructions that the IDE uses when you perform commands on your project, such as compiling source files, running the application, running tests, debugging, compiling Javadoc documentation, and building JAR files. In addition, you can use this build script to run Ant targets on your project from outside of the IDE.

You can have multiple projects open at the same time, and the projects can be linked through dependencies. Project-specific commands in the Build and Run menus act on the currently designated main project. The main project is marked in bold, as shown in Figure 3-1.

Figure 3-1. Projects window


What Is Ant, and Do I Need to Know Anything About It?

Ant is the tool that NetBeans IDE uses for running project-related commands. If you have no interest in Ant as such, you can completely ignore it, much as you would never bother decoding project metadata in another IDE. However, if Ant is already the lifeblood of your build process, you can set up NetBeans IDE to accommodate your existing build process, either by overriding specific Ant targets that the IDE generates or by providing your own Ant script.

Ant was developed by the Apache Software Foundation to automate routine developer tasks, such as compiling, testing, and packaging your application. Ant is similar to Make but has the advantage of being written in Java, so it works across multiple platforms. You can also use Ant to invoke other processes, such as checking out sources from version control, obfuscating classes, and so on. In addition, you can write Java classes to extend Ant's functionality. On big development efforts, Ant is often used as a production tool to compile and package the whole application for distribution.

Ant scripts themselves are written in XML. They are divided into high-level targets, which are collections of tasks that are run for specific purposes, such as cleaning the build directory, compiling classes, and creating packaged outputs.

Other IDEs provide integration with Ant to support writing and running of build scripts. NetBeans IDE takes this a step further by making Ant the backbone for all project-related commands in the IDE. When you create an IDE project, the IDE generates an Ant script for you with targets for, among other things, compiling, running, debugging, and packaging your application. When you run project commands in the IDE (such as Build Main Project or Run Main Project), the IDE itself is calling an Ant script.

The fact that the IDE's project system is based on Ant provides another advantage: Other developers do not have to use NetBeans IDE to build the project. It is possible to run an IDE-generated Ant script from another IDE or the command line, which could be particularly useful for doing production builds of your team's application.


Unlike in 3.x versions of NetBeans IDE, explicit creation of an IDE project is a primary step in your workflow in versions of the IDE beginning with 4.0. In NetBeans IDE 3.x versions, "projects" were a peripheral paradigm with a limited feature scope.

Also, as opposed to the filesystem concept in NetBeans IDE 3.x, the folders included in the Projects and Files windows do not necessarily represent the classpath. In fact, it is OK to have multiple projects open, even if they have no relationship to the main project you are working with. Likewise, a project you are working on can depend on projects that you currently do not have open.




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