javadebuggingremote-debugging

Remote debugging a Java application


I have a java application running on linux machine. I run the java application using the following:

java myapp -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000, suspend=n

I have opened port 4000 for TCP on this Linux machine. I use eclipse from Windows XP machine and try to connect to this application. I have opened the port in windows also.

Both machines are on the LAN but I can't seem to connect the debugger to the Java application. What am I doing wrong?


Solution

  • Edit: I noticed that some people are cutting and pasting the invocation here. The answer I originally gave was relevant for the OP only. Here's a more modern invocation style (including using the more conventional port of 8000):

    java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n
    <other arguments>
    

    Note: With address=8000 (as used above), the debug server will only listen on localhost (see What are Java command line options to set to allow JVM to be remotely debugged?). If you want the server to listen on all interfaces, to be able to debug across the network, use address=*:8000. Obviously only do this on a restricted, trusted network...

    Original answer follows.


    Try this:

    java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n myapp
    

    Two points here:

    1. No spaces in the runjdwp option.
    2. Options come before the class name. Any arguments you have after the class name are arguments to your program!