In the Vagrantfile, do :
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network :public_network
# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
config.ssh.forward_agent = true
And:
# The java process in the VM will listen on port 4040, which is the same port that the remote debugger will connect to
# They don't have to be the same, but...why the heck not?
config.vm.network :forwarded_port, guest: 4040, host: 4040
- From the (host) 'real' machine, do:
#Here, -L 4044 is the port that the IDE debugger will connect to (in the 'host' - real - machine)
#and the :4044 on the right of the IP address is the port where the java process being debugged will listen on
ssh -p2222 -f -N -L 4044:127.0.0.1:4044 vagrant@localhost (runs in the background)
ssh -p2222 -N -L 4044:127.0.0.1:4044 vagrant@localhost (runs in the foreground)
- Start the java process to be debugged (in the VM):
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=40444 -jar ./target/test.jar
Note the 'suspend=y' here : this means that the (command line java application) will 'wait' for the debugger to connect; If you are launching a webservice (say, a jetty/dropwizard), then, this could be 'suspend=n'