7.3. Catching Ant Build File Syntax Problems

Problem

You have a problem with a build file, and you would like to track it down.

Solution

The current version of Ant displays syntax errors for Ant scripts only when you try to run them. However, Eclipse 3.0 does catch and display syntax errors as they’re created.

Tip

This is an Eclipse 3.0-only solution.

Discussion

Eclipse does offer some support for catching syntax errors when you write Ant scripts. However, the Eclipse editor catches syntax errors only if your XML documents are not well formed in the XML sense (e.g., nesting errors, omitting quotes for attribute values, etc.). You can see an example in Figure 7-7, where we’ve omitted the quote in front of the text jarFile, which is being assigned to an attribute in the <property> element.

An XML error in an Ant script

Figure 7-7. An XML error in an Ant script

Note, however, that although the Ant editor indicated that the XML was not well formed, it entirely missed the fact that the <property> element’s name attribute is misspelled as nane, as shown in the figure.

On the other hand, when you try to run this script, Ant will realize there’s a syntax error, and you’ll get the results you see in Figure 7-8, where the syntax error is indicated.

An Ant error

Figure 7-8. An Ant error

Eclipse will show you the syntax error when you try to run ...

Get Eclipse Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.