Debug Ant task from eclipse

14,354

You need to start ANT with the remote debug enabled by entering the following before you run ANT.

set ANT_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

This will cause the JVM running ANT to pause until you attach your debugger.

Next you'll need to modify the classpath ANT is using in order to pickup the classes that form the custom task you're writing. I don't think there's a way to do this easily with environment vars, so the quickest thing is to just edit the ant.bat file.

Now when your custom task is run, it will stop at any breakpoints in your IDE.

Share:
14,354

Related videos on Youtube

clamp
Author by

clamp

hello

Updated on September 15, 2022

Comments

  • clamp
    clamp over 1 year

    I am developing a custom ant task with java in the eclipse ide.

    is it somehow possible to debug it? that is put a breakpoint on the java line and when ant is executed, it stops there and i can step through the code?

    edit: since this question has been closed as duplicate, i want to elaborate why it is quite different.

    i am looking to debug the java code that makes up an ant task and not the just the steps of an ant build. the answers already helped me partially, but i still need to figure out why my eclipse doesnt have Debug Remote Java Application.

    • Perception
      Perception about 11 years
      Please do not close this question as a dup of the linked one. It is actually quite different.
  • clamp
    clamp about 11 years
    thanks, is a simple <taskdef> enough to guide ant to the classes that make up my task?
  • Nick Holt
    Nick Holt about 11 years
    No, taskdef just takes the classname, you'll need add the IDE's output directory to the ANT's classpath in order for the ANT JVM to find the class.
  • kc2001
    kc2001 over 6 years
    According to ant.apache.org/manual/running.html, it looks like you can add your library to the classpath using the -lib command line option for ant 1.6 and above. This would be preferable to editing the batch file.