Mar 23, 2014

Remote debugging for Tomcat and IntellJ on Max OS X

IntellJ supports remote debugging for Tomcat. It is really convenient for debugging. This entry shows how to adopt remote debugging with Tomcat and IntellJ.

My dev environment


  • Max OS X 10.9.2
  • Java 1.8.0
  • Tomcat 8.0.3

Set up

Tomcat
  1. Create a new file called <Tomcat install directory>/bin/setenv.sh. (This file will be automatically read by catalina.sh)
  2. Add the following content to setenv.sh. 8080 is a port number for Tomcat. Please specify for your tomcat.
    • CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8080,server=y,suspend=n"
  3. Start Tomcat normally using startup.sh.

IntellJ
  1. Select "Run -> Edit Configuration" then "Run/Configuration" screen is open.
  2. Specify "Name" like "Tomcat".
  3. Specify "Port", which is the same number as Tomcat's port numer

Debug

  1. If you want to start debugging on IntellJ, just select "Run -> debug 'Tomcat'". 
  2. If IntellJ shows a message like below, you are already connected.
    • Connected to the target VM, address: 'localhost:8080', transport: 'socket'
  3. Now you can debug. Please refer here for more detail about debugging by IntellJ.

No comments:

Post a Comment