Search code examples
javadebuggingvagrantremote-debuggingportforwarding

How to remotely debug java app and forwarding the port to virtual machine?


I want to start a java application in a host machine (windows 7) with debugging enabled

-Xdebug 
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

Then I want to start a virtual machine through vagrant and forward the port 5005 to the guest machine.

On the guest machine I want to connect to port 5005 and debug the app.

config.vm.network "forwarded_port", guest: 5005, host: 5005, protocol: 'tcp'
config.vm.network "forwarded_port", guest: 5005, host: 5005, protocol: 'udp'

The problem is that once the virtual machine is running the java app crashes immediately when I start it. When I change the debug port to something else than 5005 the app starts.


Solution

  • As mentioned in comments you should not forward port on the machine where the the JVM is running, it is the Java App that needs to receive traffic on that port and startup fails most likely because the port has already been forwarded.

    Forwarding on the other end is not necessary either, you can just debug on <target>:<port> instead.