Introduction
So I'm doing more and more development using pure Intellij for Liferay 7 / DXP, even debugging.
I thought I'd share how I do it in case someone else is looking for a brief how-to.
Tomcat Setup
So I do not like running Tomcat within the IDE, it just feels wrong. I'd rather have it run as a separate JVM with it's own memory settings, etc. Besides I use external Tomcats to test deployments, run demos, etc., so I use them for development also. The downside to this approach is that there is zero support for hot deploy; if you change code you have to do a build and deploy it for debugging to work.
Configuring Tomcat for debugging is really easy, but a quick script copy will make it even easier.
In your tomcat-8.0.32/bin directory, copy the startup script as debug. On Windows that means copying startup.bat as debug.bat, on all others you copy startup.sh as debug.sh.
Edit your new debug script with your favorite text editor and, practically the last line of the file you'll find the EXECUTABLE start line (will vary based upon your platform).
Right before the "start", insert the word "jpda" and save the file.
For Windows your line will read:
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
For all others your line will read:
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
This gives you a great little startup script that enables remote debugging.
Use your debug script to launch Tomcat.
Intellij Setup
We now need to set up a remote debugging configuration. From the Run menu, choose Edit Configurations... option to open the Run/Debug Configurations dialog.
Click the + sign in the upper left corner to add a new configuration and choose Remote from the dropdown menu.

Give the configuration a valid name and change the port number to 8000 (Tomcat defaults to 8000). If debugging locally, keep localhost as the host; if debugging on a remote server, use the remote hostname.

Click on OK to save the new configuration.
To start a debug session, select Debug from the Run menu and select the debug configuration to launch. The debug panel will be opened and the console should report it has connected to Tomcat.
Debugging Projects
If your project happens to be the matching Liferay source for the portal you're running, you should have all of the source available to start an actual debug session. I'm usually in my own projects needing to understand what is going on in my code or the interaction of my code with the portal.
So when I'm ready to debug I have already built and deployed my module and I can set breakpoints in my code and start clicking around in the portal.
When one of your breakpoints is hit, Intellij will come to the front and the debugger will be front and center. You can step through your code, set watches and view object, variable and parameter values.
Intellij will let you debug your code or any declared dependencies in your project. But once you make a call to code that is not a dependency of your project, the debugger may lose visibility on where you actually are.
Fortunately there's an easy fix for this. Choose Project Structure... from the File menu. Select the Libraries item on the left. The right side is where additional libraries can be added for debugging without affecting your actual project dependencies.
Click the + sign to add a new library. Pick Java if you have a local source directory and/or jar file that you want to add or Maven if you want to download the dependency from the Maven repositories. So, for example, you may want to add the portal-impl.jar file and link in the source directory to help debug against the core. For the OSGi modules, you can add the individual jars or source dirs as you need them.

Conclusion
So now you can debug Liferay/Tomcat remotely in Intellij.
Perhaps in a future blog I'll throw together a post about debugging Tomcat within Intellij instead of remotely...


