Remote debugging with IntelliJ IDEA
2013-04-03
Last modified on 2022-03-30Tools
Vagrant
Vagrant is a virtual development environment tool. It uses VirtualBox to create easy to use virtual server. A sweet goodbye to the "But it works on my computer !" when co workers can't run the project... The vagrant box IP should be added to the hosts :
192.168.33.10 mysite.local
IntelliJ Idea
IntelliJ Idea is a very nice IDE. I tried it last christmas because it was 75% off... And I can't look back (I see you in the corner, Eclipse; stay there).
Setup
- Follow the tutorials from Vagrant website to setup your java environment. (I actually began with a vagrant default box (Ubuntu Lucid), and I updated it to Quantal). My vagrant file is here.
- Install Tomcat on the vagrant box.
- I am actually working on an OpenCms project, so deploy this sweet sweet cms somewhere.
Debug configuration
Enable JVM debug
Edit /etc/default/tomcat7 (on Ubuntu) and uncomment the following line:
JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
Enable Java debug in the jar
We use an ant task to generate our OpenCms modules. To enable debug, I have the following property :
<property name="java.opts.debug" value="on" /> <!-- "on" or "off" -->
And the javac task:
<javac srcdir="${folder.src}" destdir="${folder.build.jar.classes}" classpathref="compil.classpath" debug="${java.opts.debug}" debuglevel="lines,vars,source" source="1.5" target="1.5" />
IntelliJ IDEA
In the edit configuration :
Debug session
Start tomcat with the debug options, then, in IntelliJ IDEA:
This load the debugging tools from Intellij, and you can add breakpoints to your code and follow stuff...
Bi-Winning ?
Not yet. You can't hot-deploy modified classes (or I haven't found it yet) as you can do locally.
Word of the end ?
The end.