Search code examples
javaeclipseremote-debugging

remotely debugging a server/client application with eclipse


The to start my server/client I pass the client as a command line argument to the server and both processes are startet.

java -cp bin this.is.an.example.server "java -cp C:\this\is\another\example\bin\client main.Client"

in an attempt to debug it comfortably I installed eclipse by adding the client in the servers run configurations as an argument. It worked. Unfortunately this way I only able to debug the server. I had no way to access the client during runtime as it runs in another process.

So I started searching for a solution and found some tutorials like this for example tutorial_1

I added to my command line java -cp bin this.is.an.example.server "java -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:56111,suspend=y -cp C:\this\is\another\example\bin\client main.Client"

To my client in eclipse I added, like figure 6 in the tuttorial, a remote-debug confuguration.

When I debug in eclipse it says

Waiting for vm to connect to port 56111

but nothing happens.

So here are my problems:

  1. am I doing it the right way? or is there another, maybe simplier way to debug my client? Any suggestions?
  2. if remote debugging is fine. is it possible to start remote debugging by passing the argument to my server which then starts the client with Process process = Runtime.getRuntime().exec(command);?

Solution

  • Just read: http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/conninv.html#Transports

    In contexts where a client is attaching to a server, socket transport addresses have the format ":" where is the host name and is the socket port number at which it attaches or listens. In contexts where a server is waiting for a client to attach, the address consists of the port number alone (the host name is implicit).

    And:

    name: address

    required: yes, if server=n no, otherwise

    default value: ""

    description: Transport address for the connection. If server=n, attempt to attach to debugger application at this address. If server=y, listen for a connection at this address.

    From my understanding with such invocation:

    java -cp bin this.is.an.example.server "java -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:56111,suspend=y -cp C:\this\is\another\example\bin\client main.Client"
    

    the client app has the configuration to try to connect to 127.0.0.1:56111. And from what I understood you'd like to debug the server, so I think you should change the invocation to:

    java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=56111,suspend=y -cp bin this.is.an.example.server "java -cp C:\this\is\another\example\bin\client main.Client"
    

    However if the client app should be listening for connections it should be like that:

    java -cp bin this.is.an.example.server "java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=56111,suspend=y -cp C:\this\is\another\example\bin\client main.Client"
    

    Consider also changing -Xrunjdwp to -agentlib:jwdp if Java >= 5.0.