Maven, Jetty and IntelliJ Debugging

 In Technical

We use IntelliJ as our primary IDE and the majority of our web projects run in Jetty during development. This is a quick guide to getting the debugger hooked up to an application.

Since Jetty is launched from maven we need to do the following:

From your prompt run the following command to allow you to connect to the application remotely. Post JDK1.3.x

export MAVEN_OPTS=”-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005″Pre JDK1.3.x
export MAVEN_OPTS=”-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005″

Go to IntelliJ and click on Run -> Edit Configurations. Then click on the + button followed by Remote to add a remote configuration. Make sure you are listening on the right port (5005) and click apply.When you start Jetty from Maven you will see – Listening for transport dt_socket at address: 5005

Then you go into IntelliJ, choose the Remote configuration that you have just set up, and press debug. Now you can set breakpoints and debug the code.

Update 7th May

As it turns out, you can also run jetty using “mvnDebug jetty:run” which has the same effect. Just remember to choose the correct socket address in the IntelliJ configuration.

Start typing and press Enter to search