Maven: How to Debug

Version 6

    Step 1: Set Up Your IDE

    Configure Remote Debugging in IDEA

    You'll want to create a configuration for Tomcat.

    1. Select Run -> Edit Configurations

    2. Click Add New Configuration

    3. Select Remote

    4. Name the Configuration

    5. Set the Port to 8787

    6. Uncheck Make in the Before Launch section

    7. Uncheck Display settings before launching

    8. Click Apply

    Picture1.png

    Configure Remote Debugging for Eclipse

    This is as simple as creating a Remote Java Application as a Debug Configuration.

     

    1.  Drop down the Debug button, and choose the Debug Configurations... item

    Picture2.png

    2.  Select Remote Java Application in the Configurations list and click the New Configuration button.

    Picture3.png

    3.  Name the configuration.

    4.  Specify the project to debug (web).

    5.  Specify the port (8787).

    Picture4.png

    6.  Click Apply.

    7.  Click Debug.

     

    To set up a Debug Configuration for your unit tests, specify 5005 as the port.

    Step 2: Remotely Debug Tomcat

    1. Be sure you have a remote configuration for Tomcat to port 8787.  Repeat the steps above for creating a Remote Debugger

    2. Run this with Maven:

      mvn -Dcargo.wait=true -P int integration-test
    3. In IDEA, select the Runtime Configuration you created from the drop down in the tool bar

    4. Run -> Debug

    5. IDEA will connect to the Tomcat process and display the Debug view

    Debugging Unit Tests

    Debugging unit tests is very simple with Maven and Surefire.  All you have to do is specify the maven.surefire.debug sytem property on the command line:

    mvn -Dmaven.surefire.debug test

    To specify a specific test use

    mvn -Dmaven.surefire.debug -Dtest=<unqualified-classname> test