Java Debugging Maven Test

Submitted by code_admin on Tue, 07/13/2021 - 14:14

Steps taken to debug maven tests in Java inside a docker container:

Run docker container with maven exporting port 8000

  1. docker run --rm -it -p 8000:8000 -v ~/.m2:/root/.m2 -v $(pwd):/extdir maven:3-amazoncorretto-11 /bin/sh

Copy source and pom:

  1. cp -r /extdir/src /src
  2. cp /extdir/pom.xml /pom.xml

Run maven tests waiting for debugger connection:

  1. mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:8000 -Xnoagent -Djava.compiler=NONE" test

In inteliJ
Create a new run configuation + "Remote"
Attach to remote JVM. Enter host and port.

Press the debug icon and debugging should be in progress.

Links:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/debugg…

Tags

RJM Article Type
Quick Reference