5.3 Configuring Ant in Eclipse
Eclipse also lets you configure its internal version of Ant. To configure how Ant will run, select Window
Preferences, followed by the Ant item, as shown in Figure 5-7. In Eclipse, you don't need to
your build file
; Ant will try to guess which file is the build file (the build file does need to be an XML file, with a name that has the extension
). You can help Eclipse out by giving an alternate name, or a list of
, in this dialog.
Figure 5-7. Configuring the build file
You can also set Ant runtime options by selecting the Runtime node, as shown in Figure 5-8. For example, to use a more recent version of Ant in Eclipse (Eclipse 2.1.1 comes with Ant 1.5.3, but the latest version of Ant, as of this writing, is 1.5.4, and Version 1.6 is out in beta; you can get alternate Ant versions directly from Apache at http://ant.apache.org), select the Runtime item and change the JAR entries you see in Figure 5-8 to the new versions of
. You can also set Ant
in this dialog.
Figure 5-8. Configuring Ant in Eclipse
You can add new Ant tasks and types with the Tasks and Types tabs, which means that those
and types will be available to build files without having to use Ant
elements. Eclipse also lets you set global Ant properties if you select the Properties tab in this dialog. To add a new global property, click the Add button in the Properties tab, and enter a name and value for the new property.
You also have limited control over the Ant editor's options using the Preferences dialog and selecting the Ant
Editor item. The Ant editor is actually little more than a simple XML editor, but you can specify such items as the colors used in syntax highlighting, or whether the editor shows an overview ruler, as you see in Figure 5-9.
Figure 5-9. Configuring the Ant editor
The Ant editor also offers code assist. For example, if you enter
and then pause in typing, code assist will give you a list of possible Ant build file elements. Entering additional
narrows down the listfor example, entering
makes code assist give you the choice of
. Code assist will also list possible attributes of Ant elements; just click inside the opening tag of an Ant element and press Ctrl+Space. Also, letting the mouse cursor rest on one of the items in the code assist list makes Eclipse display an explanation of what that item does. For example, the explanation for the
element is "Sets a property by name, or a set of properties (from file or resource) in the project."
You can also configure Ant when you're about to run it, before selecting an Ant target to build. Right-click
, select Run Ant, and click the Main tab in the dialog that opens, as shown in Figure 5-10. You can set the location of the build file you want to use here, as well as the base directory for the build. You can also set Ant arguments in the Arguments field.
Figure 5-10. Setting the run configuration
In addition, there's also an Ant view in Eclipse, which you
Ant. This view provides an Ant-based overview of build files; to add a build file to this view, right-click the view, select Add Buildfile, and navigate to the build file you want to display. The view will display a breakdown of the build file, as you see in Figure 5-11, and you can run various Ant targets by right-clicking them and selecting Run.
Figure 5-11. The Ant view