Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a Tomcat 7.x/8.x webapp locally with IntelliJ Community (free) version in Linux?

I understand that this is possible to do with the Ultimate Edition, but is there a way to debug these applications locally in the Community Edition?

like image 587
AmirHd Avatar asked Dec 26 '14 10:12

AmirHd


1 Answers

History

If you have worked with IntelliJ Ultimate edition you have seen that it is possible to add a Tomcat configuration where you can both debug or run your Tomcat container from within IntelliJ. It is possible to get your IntelliJ Community version to do the same thing for you with a little bit of extra settings.

Relevant concepts

Tomcat JMX

This is a remote monitoring and management tool for Tomcat. JMX related settings is not needed to enable your debugging. Although it can be useful for monitoring purposes through JConsole (read more).

Different ports

You instance of Tomcat must be already up and running for the Community version to be able to attach itself to the Tomcat process. While your tomcat will be running on a port (Tomcat default is 8080), you also need to setup another port for the debugger to attach itself to your running version of Tomcat (9999 in our example).

Settings

Settings include changes you need to make to your Tomcat and configurations you need to do on your IntelliJ community edition.

Please follow the order in changes.

Tomcat side related changes

  1. Stop your Tomcat if it is running in your Tomcat bin folder through: ./shutdown or ./catalina stop

  2. Add the following line to your catalina.sh file under the commented JAVA_OPTS set statement:

    JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999"

HINT: I have used JAVA_OPTS not CATALINA_OPTS as the comments in catalina.sh suggests it is preferred to use JAVA_OPTS. However, it is possible to use CATALINA_OPTS in a similar manner to enable the debugging.

  1. Start Tomcat:

./catalina.sh start

IntelliJ related changes

enter image description here

Result

After click on debug button in your IntelliJ Community edition your debug section should open with the following line in its Console area:

Connected to the target VM, address: 'localhost:9999', transport: 'socket'

Relevant posts and links

  1. Remote debugging with Tomcat (7) and Intellij (Very useful for Window only though)
  2. IntelliJ and Tomcat.. Howto..? (Misleading as it's old)
  3. IntelliJ ultimate and community version setups (Helpful but over complicated)
  4. IntelliJ IDEA 14.0.0 Web Help/Run/Debug Configuration: Tomcat (Somewhat useful)
  5. Debugging with Tomcat and Intellij Community Edition (Old and incomplete)
like image 179
AmirHd Avatar answered Sep 19 '22 13:09

AmirHd