Steps taken to debug maven tests in Java inside a docker container:
Run docker container with maven exporting port 8000
-
docker run --rm -it -p 8000:8000 -v ~/.m2:/root/.m2 -v $(pwd):/extdir maven:3-amazoncorretto-11 /bin/sh
Copy source and pom:
-
cp -r /extdir/src /src
-
cp /extdir/pom.xml /pom.xml
Run maven tests waiting for debugger connection:
-
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…
RJM Article Type
Quick Reference