Debugging Ant files
Yes, you read it correctly. You can actually debug Ant files in Eclipse just like you debug Java files, and have all the standard debugging features available. This is probably the best functionality in the Eclipse Ant integration.
Just as we always do with Java files, place breakpoints inside targets on the lines that call the task we're interested in stepping through. To put a breakpoint on a line, simply double-click beside the line on the gray bar at the left. A green ball appears, denoting that a breakpoint has been set (see Figure 15). Temporarily enable or disable breakpoints by clicking them or disabling them in the Breakpoints view. A disabled breakpoint appears as a white ball. Note that unlike Java breakpoints, we cannot set hit counts or conditions on breakpoints -- not that we'll need them while debugging Ant files, anyway.
Figure 15. Breakpoint set on a line in the buildfile
Now, begin debugging. Right-click a target in the Ant view or the Outline view, then click Debug As > Ant Build. Just as with Java files, the buildfile pauses when the execution reaches the line on which we've set the breakpoint.
Here's the great part: Click the Step Over button in the Debug view to step through the lines in the buildfile, just as we step through Java statements (see Figure 16). As we step through each task, it will be executed and produce its output, which we can examine to see what's going wrong in the build process. The Run to Line functionality is available, too, so we can right-click a line and click Run to Line to cause buildfile execution to continue until it reaches that particular line. The process is similar to setting a temporary breakpoint on a line that's removed as soon as the line is reached.
Figure 16. Step through lines in a buildfile
The Debug view shows the call stack of the tasks currently being executed. If a task calls another target -- say, antcall -- that target appears above the current task in the call stack.
A Variables view is also available (see Figure 17). Open this view to see all the Ant properties, which are the Ant equivalent of variables. The properties are shown grouped in three parts:
- System properties: Properties set from the system for the build
- User properties: Properties such as those set using the
- Runtime properties: Properties defined in a buildfile that are set during runtime
Figure 17. The Variables view shows all properties
Note that unlike the Java debugger, the Ant debugger doesn't allow us to change the value of the properties shown in the Variables view.