How to debug Spring Boot application with Eclipse?
JavaSpringEclipseDebuggingSpring BootJava Problem Overview
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 should I listen to? And is there a setting on my webapp I have to set to enable debugging?
Java Solutions
Solution 1 - Java
Why don't you just right click on the main()
method and choose "Debug As... Java Application"
?
Solution 2 - Java
There's [section 19.2 in Spring Boot Reference][1] that tells you about starting your application with remote debugging support enabled.
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
-jar target/myproject-0.0.1-SNAPSHOT.jar
After you start your application just add that Remote Java Application configuration in Run/Debug configurations, select the port/address you defined when starting your app, and then you are free to debug.
[1]: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-running-as-a-packaged-application "Spring Boot Reference"
Solution 3 - Java
Easier solution:
Instead of typing mvn spring-boot:run
,
simply type mvnDebug spring-boot:run
You will still need to attach the debugger in Eclipse by making a new Debug Configuration for a "Remote Java Application" on the relevant port.
Solution 4 - Java
I didn't need to set up remote debugging in order to get this working, I used Maven.
- Ensure you have the Maven plugin installed into Eclipse.
- Click Run > Run Configurations > Maven Build > new launch configuration:
- Base directory: browse to the root of your project
- Goals:
spring-boot::run
.
- Click Apply then click Run.
NB. If your IDE has problems finding your project's source code when doing line-by-line debugging, take a look at [this SO answer][1] to find out how to manually attach your source code to the debug application.
Hope this helps someone!
[1]: https://stackoverflow.com/questions/21794633/debug-spring-mvc-with-eclipse-and-tomcat-issue "Debug Spring MVC with eclipse and Tomcat issue"
Solution 5 - Java
How to debug a remote staging or production Spring Boot application
Server-side
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
.
Client-side (developer machine)
Open an SSH port-forwarding tunnel to the server: ssh -L 8002:localhost:8002 [email protected]
. 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.
Solution 6 - Java
Run below command where pom.xml
is placed:
mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
And start your remote java application with debugging option on port 5005
Solution 7 - Java
The best solution in my opinion is add a plugin in the pom.xml, and you don't need to do anything else all the time:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9898
</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Solution 8 - Java
Solution 9 - Java
Right click on the spring boot project -> debug as -> spring boot App
. Put a debugger point and invoke the app from a client like postman
Solution 10 - Java
Please see <http://java.dzone.com/articles/how-debug-remote-java-applicat> to enable the remote debugging. If you are using tomcat to run your application, start tomcat with remote debug parameters or you can start tomcat with JPDA support by using following command.
Windows
<tomcat bin dir>/startup.bat jpda
*nix
<tomcat bin dir>/startup.sh jpda
this will enable remote debugging on port 8000
Solution 11 - Java
With eclipse or any other IDE, just right click on your main spring boot application and click "debug as java application"
Solution 12 - Java
This question is already answered, but i also got same issue to debug Springboot + gradle + jHipster,
Mostly Spring boot application can debug by right click and debug, but when you use gradle, having some additional environment parameter setup then it is not possible to debug directly.
To resolve this, Eclipse provided one additional features as Remote Java Application
by using this features you can debug your application.
Follow below step:
run your gradle application with
./gradlew bootRun --debug-jvm
command
Now go to eclipse --> right click project and Debug configuration --> Remote Java Application.
add you host and port as localhost and port as 5005 (default for gradle debug, you can change it)
Refer for more detail and step.