Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Java code when using ANT script in Eclipse

I have a java class and I need to debug it (put breakpoints and continue using F6). I am using ANT script to init, build, deploy and run the code. I am using:

<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" debuglevel="lines,vars,source">  ..........  </javac> 

But when I place the breakpoint in a line in my foo.java class and I run the ant script (the run part, Right Click on run-->Debug As-->Ant Build), Eclipse does not stop at that line of code.

What am I missing out?!

like image 709
zengr Avatar asked Mar 09 '10 05:03

zengr


People also ask

How do I debug an Ant script in Eclipse?

Open the Ant view (Window -> Show view -> Ant). If the build file isn't in the view then you can simply add it. Once added right click on the ant target you want to run and select Debug as -> Ant build. The Debug perspective should open up and the process should stop at your breakpoint where you can step through it.

How do I debug Ant task?

Put your ant task in the build file, run Ant in debug mode, connect your eclipse to the ant process, and it the build will stop at the break points in your Ant task, where you can actually debug your task in the "real" environment.


1 Answers

(Wasn't able to comment on the given answer, so have to make another answer)

I realized that when launching Ant from Eclipse, you'll have to add fork="true" to the <java> task. Also, it was first not clear to me how to write nested jvmargs, so here goes an example:

<java classname="..." fork="true">   <jvmarg value="-Xdebug" />   <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5432" />   ... </java> 
like image 59
Samuel Lampa Avatar answered Sep 20 '22 08:09

Samuel Lampa