ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Integrating Ant with Eclipse, Part 2
Pages: 1, 2, 3

Using a Different Version of Ant

Eclipse comes with Ant 1.6.1, but it's possible to use a different version. Open the Ant preferences page by selecting Window→ Preferences→ Ant→ Runtime and clicking the Classpath tab.



When Eclipse runs Ant, it looks for the appropriate classes on the Ant classpath, as set in the Ant Home Entries item. To change the Ant Home Entries, click the Ant Home button and choose the Ant installation you wish to use.

TIP: If you don't want to change the classpath, you can run Ant as an external tool from Eclipse. To do that, select Run→ External Tools→ External Tools to open the External Tools dialog. Click the Program item and then the New button. Enter a name for the new tool (such as "Ant 1.8" or whatever is appropriate). Next, to the Location field, click the Browse File System button and navigate to ant.sh or ant.bat, whichever is right for your operating system, and click Open. The External Tools dialog will reappear; in the Arguments field, enter any arguments you want to pass to Ant. Finally, in the Working Directory field, enter the directory of the build file you want to use and click Run to launch the new version of Ant. The problem with doing this is that you won't have easy access to predefined values that you have while working inside Eclipse. In most cases, it's far better to use Ant from inside Eclipse when building Eclipse projects.

Using the Ant View

Eclipse comes with a dedicated view for working with Ant—called the Ant view—which is a window that gives you an overview of the targets in build files. To open this view, select Window→ Show View→ Ant; the Ant view appears at right in Figure 11-12.

Figure 11-12
Figure 11-12. The Ant view

The toolbar in this view contains these buttons (from left to right):

  • Add Build Files

  • Add Build Files with Search

  • Hide Internal Targets

  • Run the Default Target

  • Remove Selected Build File

  • Remove All Build Files

To add a build file to the Ant view, click the Add Build Files button, opening the Choose Location dialog. In the left box, select the Eclipse project you want to use, and in the right box, select the build file you want to add to the Ant view. Click OK, adding the build file to the Ant view.

TIP: In Windows, you can add build files to the Ant View with drag and drop.

Besides giving you an overview of a build file, the Ant view lets you run build files. Select a build file in the Ant view and click the Run the Default Target button. Or right-click a target and select the Run item in the context menu that appears. Double-clicking a build file in the Ant view opens it in the Ant editor (as does right-clicking the build file and selecting the Open With→ Ant Editor item).

Using Ant with Eclipse is a potent combination. Eclipse allows you to develop and debug code, and Ant lets you build and deploy it. Both of these tools are free for the downloading. It's a combination I recommend.


View catalog information for Ant: The Definitive Guide, Second Edition

Return to ONJava.com.