views:

1009

answers:

2

Hi,

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?!

+1  A: 

In the <java> ant task you should add two jvm parameters (<jvmarg> IIRC) to turn on debugging:

 -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5432

This will launch the java program with debugging turned on and the program will be ready to accept debugger connections on port 5432. Then you should use your IDE's remote debugging facility and direct it to connect to port 5432.

jkff
Depending on where the breakpoint is set, you may need to set "suspend=y" in the command line arguments -- the JVM will block startup until you connect the debugger.
Phil M
also, the ant script does not need to be started in debug mode for this ... in fact if they (<java> task and java process that launched ant) have the same port the java task won't start.
saugata
+1  A: 

(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>
Samuel Lampa
Better solution ;)
zengr