Note here, the value 4000. This is the port that we are using for remove debugging. When you start your app with the Maven Tomcat plugin, you should see something like this, that means, the app is listening for remote debugging connections:

...
Listening for transport dt_socket at address: 4000
...

Configuring remote debugging in IDEA

For this you have to add a new Debug configuration that can be done by selecting the Run -> Edit configurations menu item. Here click the plus sign, to add a new configuration and select Remote.

The new Remote debugging configuration is immediately created. You can give it a name, and set the port to 4000. Here is an image about how I set it up:

After you configured it, click OK, select the created configuration and start debugging with the green button that resembles a bug.

You are all set. You can add breakpoints and debug your running app remotely.

What’s with the -Xnoagent -Djava.compiler=NONE options?

You may see that in some places the remote debugging configuration contains the

-Xnoagent -Djava.compiler=NONE

options as well. These options were only required for very old JVMs so you can forget about them now.

Organize imports on the fly

The first way is to tell the IDE to automatically organize the imports on the fly. This means that when you are editing a file, if the IDE sees some imports left unused, it automatically removes them, so you don’t have to worry about manually doing that.

In IntelliJ IDEA, you can do this in the File -> Settings… window. Check the “Optimize imports on the fly” checkbox:

Remove unused imports upon commit with Git

You can also remove the unused imports when committing in Git.

Right click on the project where you would like to commit and select Git -> Commit Directory…