11:29 AM |
Tuesday, July 23, 2013
Debug with Tomcat
Start tomcat with this command:
catalina.sh jpda start
(if you do a "tail -100f catalina.out" it should display something like
this at the bottom: "Listening for transport dt_socket at address:
8000")
>> thats it! now goto step (2) to config IntelliJ
Debug with Jetty
B.1. Add maven options property inside your bash profile.
export MAVEN_OPTS="-XX:+CMSClassUnloadingEnabled -XX:PermSize=512M
-XX:MaxPermSize=1024M -Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"
B.2. Save and source: source ~/.bashrc
B.3. Then Run jetty as usual in your web app: mvn jetty:run
(Now you should see something like
this at the bottom of jetty log: "Listening for transport dt_socket at address:
8000")
>> thats it! now goto step (2) to config IntelliJ
------------------
2. Inside IntelliJ: Run -> Edit config -> Click (+) sign -> choose Remote -> give the host and debug port (default port of tomcat is 8000/for jetty use the port you used) -> Click OK
!! Thats all!
3. Now put some debug points inside the webapp.
4. Run -> Click Debug
now the Debugger will get connected with JVM. you will see a message saying "Connected to the target VM, address: 'localhost:8000', transport: 'socket'" yes thats it!
Now just browse your webapp as you normally do. IntelliJ will hit the debugger when you reach the debug point which you put earlier at the web app code.
(You will notice the browser is not responding when the Debugger hit some debug point.)
Notes: Don't forget to use the same source code you used to deploy the webapp. i mean WAR package should be a deployed output package of the relevant source code you gonna debug with. If its not crazy things will happen of course. ;-)