Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging jsp with spring-boot and IntelliJ

I'm developing a web app (war packaging) using spring-boot, jsp and an embedded tomcat. The app runs fine and I can debug java files without any problems if I add a maven run configuration with the spring-boot:run goal.

But when I try to add a breakpoint in one of my jsp files IntelliJ shows this error: 'Breakpoint doesn't belong to any class'.

If I configure IntelliJ to use an external tomcat server then the jsp debugging works perfectly.

Is there a way of debugging jsp using the spring-boot maven goal? Is this a problem with spring-boot or with maven run configurations in IntelliJ?

I'd really like to be able to use the full spring boot capabilities from my dev environment.

Thank you.

like image 652
asolana Avatar asked Apr 25 '14 23:04

asolana


People also ask

How do I debug a JSP file in IntelliJ?

Create a run configuration: Run > Run Configuration > click the + button, and pick JSR45 Compatible Server, and then in the dialog that opens, select Remote, and set server host and port. Setting Application Server: Generic should work fine. Make sure you set the correct port in Startup/Configuration > Debug.

Can we use JSP with spring boot?

Undertow will not support JSP if used as an Embedded Servlet Container. If deploying in a web container, our @SpringBootApplication annotated class should extend SpringBootServletInitializer and provide necessary configuration options. We can't override the default /error page with JSP.

Can you debug JSP files?

You can use the debugger to detect and diagnose errors in your application. You can control the execution of your program by setting breakpoints, suspending threads, stepping through the code, and examining the contents of the variables.


1 Answers

The problem is that spring boot spawns another process for the app. You have to tell boot that you want to debug and not just run the command for maven or gradle in debug mode. :-( See:

  • http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-remote-debug-gradle-run
  • http://docs.spring.io/spring-boot/docs/1.1.4.BUILD-SNAPSHOT/maven-plugin/examples/run-debug.html

Update: For my current project, I just provide a class to initialize spring boot in a war file. (See corresponding howtos to use spring boot for war files that are deployed in real webcontainers)

So during development of frontend stuff I use springboot:run to have quick reloads of resources etc. and for debugging of java code I deploy the stuff into a tomcat in debug mode. For a release I just have to decide which packaging type I want, as my app is capable of running as jar or war file.

BTW: If you want to use tomcat only stuff (special filters and so on) you can use an embedded tomcat for springboot:run as well, so your environments are more similar and you don't hunt ghost bugs ;-)

Update 2

According to https://github.com/spring-projects/spring-boot/issues/1138 you can just run the main method of your boot app to debug. I guess it helps to have used the maven target at least once so everything is compiled/copied etc. It works for me! :-)

Update 3 According to the spring boot team, they changed the way spring-boot:run works, so beginning with 1.2 you should be able to use the debug mode for the maven target as well, although their recommend way to start spring boot apps is always to start the main method.

Update 4 I can confirm that beginning with spring 1.2 you can directly run the maven targets in debug mode to be able to set breakpoints etc.

like image 72
Patrick Cornelissen Avatar answered Nov 06 '22 13:11

Patrick Cornelissen