Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java jdb remote debugging command line tool

Tags:

java

jdb

anyone have any experience using this? if so, is it worth while?

like image 833
bmw0128 Avatar asked Sep 17 '08 21:09

bmw0128


2 Answers

I just used jdb for the first time yesterday and am really pleased with the results. You see, I program in Eclipse on my laptop, then deploy to a VM to make sure the whole shebang still works. Very occasionaly, I'll have to work on something that gets executed standalone, as a commandline. These things sometimes need debugging.

This has always been a problem, because I don't want to go to the trouble of installing Eclipse on the VM (it's slow enough already!), yet I don't know of an easy way to get it to connect to my commandline-running class before it finishes running.

jdb to the rescue! It works a treat - small and functional, almost to the point where it is bare... this forces you to apply your mind more than you apply the tool (like I said here).

Make sure to print out the reference (solaris, windows, java 1.5 - I think they're all about the same, really) and have your source code open and browsable on your second screen. I hope you have a second screen, or you'll be alt-tabbing a lot.

like image 150
Johan Avatar answered Sep 28 '22 04:09

Johan


Assume your program is started by the following command:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=<port> <class>

You can attach to this process by jdb:

jdb -attach <port>

In some cases you need to use the following command .

 jdb -sourcepath \.src -connect com.sun.jdi.SocketAttach:hostname=localhost,port= <port>
like image 43
Evans Y. Avatar answered Sep 28 '22 04:09

Evans Y.