Debug Java application at startup

This may seem overly naive, but it has always been difficult for me to debug the java class during server startup. Here is the scenario:

  • The Java application is hosted on the tomcat server.
  • Suppose there is a class that is called when the tomcat server starts.
  • As soon as I stop the tomcat instance for reboot, eclipse debugging will stop, and I can only start debugging after the application starts and starts.
  • Now how do I debug this class on eclipse?

Thanks for the help in advance.

+4
source share
2 answers

You need to pass the "wait for debugger to connect" flag to tomcat. This way, the launch will wait until you are connected, and thus you will not miss the breakpoint.

Take, for example, those java options that allow tomcat to listen on the debugger:

-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8797,server=y,suspend=y 

Waiting for the debugger connection flag is the suspend=y entry in the line above.

+12
source

Debugging classes at startup should work without problems. For example, suppose you implement the ServletContextListener class . The affiliation of the contextInitialized method is invoked during the launch of Tomcat (or, to be more precise: during the deployment of your application).

You can set breakpoints in this class. At this point, Tomcat is already fully running and there should be no debugging problems.

+2
source

Source: https://habr.com/ru/post/1435899/


All Articles