2009-04-09

How to Breakpoint Debug Java Code Running in Java Service Wrapper?


Java Service Wrapper: software product helps wrap Java code running as Windows service or UNIX/Linux daemon process.


Prerequisite:
The Java code has been configured & scripted running well as a service or daemon. (such as prototype passed.) This HowTo is only for helping bug fix without extra coding / changing any config file.


Step1.
Run the Java code within the wrapper as JPDA JDWP debugable listener.

Only two points essential for this task: (search / read any other document is just wasting time...)

A. Run wrapper as Console app:

wrapper -c

B. Pass in configuration properties to start Java code with JDWP enabled:

wrapper -c wrapper.conf wrapper.java.additional.1=-Xdebug wrapper.java.additional.2= -Xrunjdwp:transport=dt_socket,address=6662,server=y,suspend=n wrapper.debug=TRUE

Important notes:
* Copy all to your batch/shell script in one line, and no space around "=" sign.
* Be sure to change the number 1 and 2 (in "additional.1 and 2") to equal to (N+1) and (N+2) while "N" is the max value of "wrapper.java.additional.n" defined in the wrapper.conf file if there is any such line.

Bonus point: reduce ping log message in the console by increasing ping.interval value at the end of the command line:

wrapper -c wrapper.conf wrapper.java.additional.1=-Xdebug wrapper.java.additional.2= -Xrunjdwp:transport=dt_socket,address=6662,server=y,suspend=n wrapper.debug=TRUE wrapper.ping.interval=600


Step2.
Hook up source code in IDE (Eclipse as example) to remotely connect to the listener port (6662 here as above) by dt_socket type.
(For details please refer to Debug Java applications remotely with Eclipse)
Simple tips here: Run -> Open Debug Dialog -> Remote Java Application -> New launch configuration, then set Connection Type to Socket Attach, Port to 6662 (as above), and don't forget to click the "Debug" button ...


Now go ahead to set breakpoints in the source code in Eclipse, and should be able to stop at a breakpoint while you test.

没有评论:

发表评论