In Eclipse EE edition, there is support to debugging web application with web container implementation like Tomcat. IntelliJ IDEA professional edtion seems have the same function. However, in IntelliJ IDEA community edition, how to do it?
This solution is found here.
First, update your Tomcat starting script file “bin/catalina.sh”, add the following content right after the “JAVA_OPTS” comment:
1 2 3
Note the “address=9999” means the network port number used by Tomcat for debugging.
Second, open IntelliJ IDEA community edition, go to “Run -> Edit Configurations”, click the “+” icon and select “Remote” from the list, then you will see a dialog like below:
Note that you only need to update the “Port:” field and the “Search sources using module’s classpath:” list, the “Command line arguments for running remote JVM” will be changed accordingly as you update the “Port” field and does not need manually update.
In the “Port:” field, just write “9999” as you set in the “bin/catalina.sh” file. In the “Search sources using module’s classpath:” list, select you project which will running in Tomcat. And remember to give a name like “Tomcat” for this “run/debug configuration” item.
Now, you just need to start Tomcat as usual(run “./bin/startup.sh”), then in IntelliJ IDEA, open “Run -> Debug ‘Tomcat’”. If everything works, you will see the following output in the “Console” tab in the “Debug” tool window:
Connected to the target VM, address: ‘localhost:9999’, transport: ‘socket’
Now you can add break point in your project source code, and access your web application hosted on Tomcat to debug.