Debugging Ant tasks in Eclipse

Today I came  an issue that required me to debug a custom Ant task that we have. While the Eclipse integrated debugger allows you to step through the targets and tasks in the build.xml file using the action Debug As -> Ant Script, it doesn’t actually let you step into the java class that implements the task. This is a major drawback, as most of the complexity (and issues :-) ) tend to be in the task implementation code.

After searching around for a bit, I came across the Eclipse Remote Debugger debug configuration. This configuration allows you to remotely debug applications, by establishing a JDWP (Java Debug Wire Protocol, part of JPDA – Java Platform Debug Architecture) connection between the running application and the debugger. After learning about this, setting up the environment to debugg Ant tasks from within Eclipse was pretty straightforward.

The first step is to setup the Ant script launcher to run in debug mode and attach to the debug server. The following should be used as JRE arguments for the Ant configuration:

-Xdebug -agentlib:jdwp=transport=dt_socket,server=y,address=8000

You can setup your Ant configuration by going to Run -> External Tools -> External Tools Configurations and creating a new Ant Build configuration. Inser the location of the build file in the main tab and setup the arguments in the JRE tab:


After the Ant configuration is setup, we need to take care of the remote debugger configuration. Go to Run -> Debug Configurations… and create a new configuration for Remote Java Application. Make sure you set the same port number that you used in the Ant configuration, and you are good to go.

Now, place the breakpoints in your build.xml and java classes. In order to debug, you need to first launch the Ant script and then attach the debugger to it. Do right click in the build.xml file and select Debug As -> Ant Script. Then go to Run -> Debug Configurations… select the Remote Ant Debugger and click Debug. The debugger will now attach to the running proccess and let you step through both the xml file and the java classes:

Have fun!

VN:F [1.9.11_1134]
Rating: 9.8/10 (24 votes cast)
VN:F [1.9.11_1134]
Rating: +18 (from 18 votes)
Debugging Ant tasks in Eclipse, 9.8 out of 10 based on 24 ratings

Popularity: 13% [?]

Tags: , , , , , , , , . 

Related Entries:
  • Eclipse SVN Plugin
  • Mylyn task manager
  • EclipseDay 2009 at the Googleplex
  • Search keywords
  • Lotus EasySync Pro


  • 13 Responses to “Debugging Ant tasks in Eclipse”

    1. Nicolas Says:

      Very usefull information. Thanks a lot.

      Nicolas

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: +1 (from 1 vote)
    2. Nithya Srinivasan Says:

      Vitor

      Thanks for this.
      Overcame a big hurdle with this
      Ours was a little bit more complicated, since we also had testng sitting in the middle

      Cheers
      Nithya

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: +1 (from 1 vote)
    3. jg Says:

      Thank you for providing this information but I cannot get it to work at all (in eclipse) Without remote debugging args I can step through the ant script. With them the task simple terminates immediately.

      I will keep looking for a solution as it must be some small configuration issue. Perhaps the eclipse cabal will address this oversight in a new version

      jg

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: 0 (from 0 votes)
    4. Jason Says:

      Nice guide although I had a little trouble when I tried this in Helios. It turns out that the -Xdebug VM argument is not required and actually stops this from working as expected even though the remote debugger seems to attach properly.

      If you are having this issue where the ant thread and remote debugging thread are running but it doesn’t seem to be hitting your breakpoint and the debugging perspective does not show the current pointer then try use these VM arguments instead:
      -agentlib:jdwp=transport=dt_socket,server=y,address=8000

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: -2 (from 2 votes)
    5. Tanel Says:

      instead of Xdebug you can try using Xrunjdwp:
      -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: +1 (from 1 vote)
    6. dress Says:

      This dress is perfect Couture Wedding Dresses Plus size Wedding Dresses fantastic dress over all Maternity Wedding Dresses The dress is simple beautiful Destination Wedding Dresses Blue Wedding Dresses Vintage Wedding Dresses I fellcompletely in love with this dress when i saw it Unique Wedding Dresses Romantic Wedding Dresses Cocktail Dresses very hard for me to find something that fits good and it is perfect Evening Dresses Recieved this dress much sooner than expected and it is beautiful Celebrity Dresses Special Occasion Dresses Blue Wedding Gowns This dress is perfect Prom Dresses Sweet 16 Dresses Quinceanera Dresses.

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: -5 (from 5 votes)
    7. robinboy Says:

      Thanks,you help me resovled a big problem.
      Thank you very much again.

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: 0 (from 0 votes)
    8. Dinesh Says:

      Hi,
      I have followed all the above specified step above but debug point does not come on java. I have specified the JVM argument in workspace JRE.
      Please help me on this.

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: 0 (from 0 votes)
    9. Gustavo Sweatmon Says:

      Thank you very much for this professional and effective help.

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: 0 (from 0 votes)
    10. Coach calgary Says:

      Thanks a lot very much for the impressive and result oriented help.

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: 0 (from 0 votes)
    11. Kindi Says:

      Impressive! Thank you very much for sharing. It is really weird such information is hard to find. Someone has to “figure it out” then share it.

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: +1 (from 1 vote)
    12. myangel Says:

      Ralph Lauren Pas Cher

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: -1 (from 1 vote)
    13. Flassari Says:

      Fantastic, works like a charm.
      Thanks.

      VA:F [1.9.11_1134]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.11_1134]
      Rating: 0 (from 0 votes)