Debugging with Maven

This short guide describes how to simplify debugging by using profiles.

First you need to add a new profile ‘debug’ to your ~/.m2/settings.xml.

<profiles>
  <profile>
    <id>debug</id>
    <properties>
      <!-- Allow configuration via system properties -->
      <debug.port>5000</debug.port>
      <debug.suspend>n</debug.suspend>
      <debug.server>y</debug.server>
      <debug.args>-agentlib:jdwp=transport=dt_socket,server=${debug.server},suspend=${debug.suspend},address=${debug.port}</debug.args>
      <!-- Configure exec plugin -->
      <exec.executable>java</exec.executable>
      <exec.args>${debug.args} -classpath %classpath ${exec.mainClass}</exec.args>
      <!-- Configure Spring Boot plugin -->
      <spring-boot.run.jvmArguments>${debug.args}</spring-boot.run.jvmArguments>
    </properties>
  </profile>
</profiles>

Whenever you want to debug, just activate the debug profile.

mvn -Pdebug exec:exec -Dexec.mainClass="com.example.demo.Application"
mvn -Pdebug spring-boot:run

Use system properties to configure the debugging parameters.

mvn -Pdebug -Ddebug.suspend=y ...