ANT, Java

Debugging ANT tasks when executing from the command line

Sometimes you may need to debug your custom Java ANT task (or even occasionally debug ANT source itself) when running from the command line. This can be achieved by setting ANT_OPTS as given below before running the “ant” command.

set ANT_OPTS=-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y


It might be a good idea to specify “suspend=y” as shown above since this will make the Java Virtual Machine (JVM) in which ANT executes to wait until you attach your debugger (from NetBeans of any IDE) along with the sources containing breakpoints.

This method can be used to debug ANT tasks running on a remote (build) server too without having to install an IDE and mounting source code in that particular server. This is made possible because the JVM opens a port for remote debugging which comes in handy not only for debugging ANT tasks but basically any java program that executes remotely.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s