4/23/2013

Remote debug setup for eclipse

Recently found one debug method very convenient for the temp stable version of project.

Which is the remote debugging for tomcat/James Server and eclipse.

For Tomcat,

First update the startup.bat file of tomcat.

 ...

rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%


:end

Add the green block at the end of the bat file.

Or set the green block to

reset DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
call "%EXECUTABLE%" %DEBUG% start %CMD_LINE_ARGS%

suspend=y/n,if you wanna to debug the app from the starting point, then you need to set this value to 'y'. Otherwise set to 'n', then you can start the remote debugging anytime after the app is up running.

When suspend=y , the app will be executed after Eclipse has connected to the remote port.
IMPORTANT! In this case, AFTER you start the app, then connect in Eclipse. Otherwise Eclipse will throw  Exception "Failed to connect to remote VM. Connection refused"

Then in Eclipse, make sure Window > Preferences > Java > Compiler 
Above setting is correctly set. And, go to Run> Debug Configuration>Remote Java Application. 
Double click to add a new app.

Make sure the debug project, server and port. And if you want terminate the project on server in eclipse, the  check the check box "Allow termination of remote JVM".

For James Server, there is one line in the run.bat.


Uncomment this line, and update the setting properties based on requirement.

Java App:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -jar stockTradingGUI.jar

Reference(Very useful tutorials):
http://javarevisited.blogspot.com/2011/02/how-to-setup-remote-debugging-in.html#ixzz1qCJwQtY2

http://javarevisited.blogspot.sg/2011/11/hotspot-jvm-options-java-examples.html

No comments:

Post a Comment