Thursday, February 4, 2010

Running Java in debug mode using Apache Ant

Configure your Java task as given below;



<java classname="org.zero.Main" fork="true" failonerror="true">
            <sysproperty key="DEBUG" value="true" />
            <jvmarg value="-Xdebug" />
            <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8999" />
            <jvmarg value="-Xnoagent" />
            <jvmarg value="-Djava.compiler=none" />
            <arg value="${project.root}/conf/preferences.xml" />
            <classpath refid="project.classpath" />
        </java>

Further,  configure your eclipse debug remote application to listen to the specified port (8999 in this case).

Also, add Thread.sleep(1000); as the first line in your main method.

Execute Java task and try connecting from eclipse, you may need to increase the thread sleep time.

1 comment:

faisal said...

Why not "suspend=y" instead of Thread.sleep?