Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Make Ant easy with Eclipse

Write, build, and debug code in the Ant editor easily

Prashant Deva, Founder, Placid Systems
Prashant Deva is the founder of Placid Systems and the author of the ANTLR Studio plug-in for Eclipse. He also provides consulting related to ANTLR and Eclipse plug-in development. He has written several articles related to ANTLR and Eclipse plug-ins, and he frequently contributes ideas and bug reports to Eclipse development teams. He is currently busy creating the next great developer tool.

Summary:  Eclipse can make working with Apache Ant easier. Discover the Ant integration features in the Eclipse integrated development environment (IDE), and learn how to write, build, and debug code in Eclipse through the Ant editor.

Date:  18 Apr 2006
Level:  Introductory PDF:  A4 and Letter (558 KB | 17 pages)Get Adobe® Reader®

Activity:  124383 views
Comments:  

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.

Place breakpoints inside targets

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
Breakpoint set on a line in the buildfile

Debug 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
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 -D option
  • Runtime properties: Properties defined in a buildfile that are set during runtime

Figure 17. The Variables view shows all properties
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.

5 of 9 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Java technology
ArticleID=108113
TutorialTitle=Make Ant easy with Eclipse
publish-date=04182006
author1-email=pdeva@placidsystems.com
author1-email-cc=