java remote debugging

Oct 10, 2019 No Comments by

Some times, in java world (and others :P ), the only fast debugging for weird bugs, is using a Remote Debugging directly to the process (in other environment).

That is possible using the argument “-Xdebug” in our “java -jar … ” call, two interesting flags are “address” and “suspend“, the first “address” allow us to expose the tcp port for the connection, if you use 0, you will have a random port. The other “suspend“, “yes” allow us to wait the process for a connection of debugging and “no” no xD.

Example

# Add the argument to the call java process
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y -jar myFavoriteJavaAppsxD.java

and our ide (in this case Eclipse), follows the next steps

  • Eclipse – “Project Explorer -> project (second click) -> Debug As -> Debug Configuration
  • Eclipse – in the eclise, “Project Explorer -> project (second click) -> Debug As -> Debug Configuration
  • Remote Java Application -> click in”new item”
  • Connect Tab – Complete the fields (host and port of the remote environment)
  • Source Tab – Add all projects of our workspace if you want to debug some part of these
  • Tips

    If you don’t have direct connection to the tcp port but yes to one ssh port, one option is use a ssh tunnel

    # Connect to the server myserver with a ssh local tunnel, in your local environment the port TCP 8000 will be redirect the traffic to the port 8000 on the server.
    ssh -L 0:8000:0:8000 user@myserver
    

    Happy debugging :P and sorry for grammatical english issue’s xD.

    Java

    About the author

    Ingeniero en Informática, Oracle Certified Master Java EE 6 Enterprise Architect, Oracle Certified Professional Java Programmer. Experto en distintas ramas de la computación y otras "yerbas" xD. Si te gusto este post, sígueme en @deerme_org, escríbeme a info AT deerme.org o contactame por linkedin.
    No Responses to “java remote debugging”

    Leave a Reply


    six * = 36