Attach IntelliJ to a remote process
Open project containing the source code
Goto Run -> Edit Configuration. Click on + and select Remote option
Change the port from 5005 to 8000 using the Port textbox under Settings. We do this because 8000 is the default port used by mvnDebug (see later)
Now add some breakpoints
Now launch your process from command line like this: mvnDebug exec:java -Dexec.mainClass=“com.mycompany.subdomain.App”
the advantage of running using mvnDebug is that you don’t have to specify the classpath(s) of any dependencies, which can get pretty long. Otherwise run the program to be debugged like this:
export JAVA_OPTS=”-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005”
suspend=y is supposed to suspend execution until a debugger is attached. then run your program:
java $JAVA_OPTS -jar
if your program takes arguments run like this mvnDebug exec:java -Dexec.mainClass=“com.xyz.abc.App” -Dexec.args=”arg0 arg1 arg2″
You should get this message:
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
[mvnDebug is now waiting for a debugger to attach before continuing program execution]
9. Now in IntelliJ, Debug the configuration you created in step 3
10. The debugger should now attach to the running process
—
http://stackoverflow.com/questions/2935375/debugging-in-maven
https://dzone.com/articles/debugging-maven-build-mvndebug
> alias mvnDebug=/usr/share/maven/bin/mvnDebug
> mvnDebug clean install
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
This ends up being the equivalent of invoking java with the proper debugging arguments:
java … -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
also http://stackoverflow.com/questions/21114066/attach-intellij-idea-debugger-to-a-running-java-process
You can change suspend=n to suspend=y to force your application to wait until you connect with IntelliJ before it starts up. This is helpful if the breakpoint you want to hit occurs on application startup.
more on mvn exec here: http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/