My Spring Boot
webapp is running just fine, and I\'d like to debug it through Eclipse.
So when launching my Remote Java Application debugger, which port
Let's assume you have successfully followed Spring Boot's guide on setting up your Spring Boot application as a service.
Your application artifact resides in /srv/my-app/my-app.war
, accompanied by a configuration file /srv/my-app/my-app.conf
:
# This is file my-app.conf
# What can you do in this .conf file? The my-app.war is prepended with a SysV init.d script
# (yes, take a look into the war file with a text editor). As my-app.war is symlinked in the init.d directory, that init.d script
# gets executed. One of its step is actually `source`ing this .conf file. Therefore we can do anything in this .conf file that
# we can also do in a regular shell script.
JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,address=localhost:8002,server=y,suspend=n"
export SPRING_PROFILES_ACTIVE=staging
When you restart your Spring Boot application with sudo service my-app restart
, then in its log file located at /var/log/my-app.log
should be a line saying Listening for transport dt_socket at address: 8002
.
Open an SSH port-forwarding tunnel to the server: ssh -L 8002:localhost:8002 myusername@staging.example.com
. Keep this SSH session running.
In Eclipse, from the toolbar, select Run -> Debug Configurations -> select Remote Java Application -> click the New button -> select as Connection Type Standard (Socket Attach), as Host localhost, and as Port 8002 (or whatever you have configured in the steps before). Click Apply and then Debug.
The Eclipse debugger should now connect to the remote server. Switching to the Debug perspective should show the connected JVM and its threads. Breakpoints should fire as soon as they are remotely triggered.