Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging in Maven?

Is it possible to launch a debugger such as jdb from Maven? I have a pom.xml file that compiles the project successfully. However, the program hangs somewhere and I would really like to launch jdb or an equivalent debugger to see what's happening.

I compile using mvn compile and launch using:

mvn exec:java -Dexec.mainClass="com.mycompany.app.App" 

I was expecting something like:

mvn exec:jdb -Dexec.mainClass="com.mycompany.app.App" 

to launch the debugger but, as usual, my expectations are incongruent with maven's philosophy.

Also, I couldn't find any documentation (on Maven's website or google) to describe how debugging works. I suspect that I have to use some plugin.

like image 901
aduric Avatar asked May 29 '10 14:05

aduric


People also ask

What is Maven debug command?

Just enter a command like this - >mvn -Dtest=TestClassName#methodname -Dmaven.surefire.debug test. It will start listening to 5005 port. Now just create a remote debugging in Eclipse through Debug Configurations for localhost(any host) and port 5005.


2 Answers

If you are using Maven 2.0.8+, run the mvnDebug command in place of mvn and attach a debugger on port 8000.

For Maven <2.0.8, uncomment the following line in your %M2_HOME%/bin/mvn.bat (and maybe save the modified version as mvnDebug.bat):

@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 

More details in MNG-2105 and Dealing with Eclipse-based IDE.

like image 115
Pascal Thivent Avatar answered Nov 13 '22 13:11

Pascal Thivent


Just as Brian said, you can use remote debugging:

mvn exec:exec -Dexec.executable="java" -Dexec.args="-classpath %classpath -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 com.mycompany.app.App" 

Then in your eclipse, you can use remote debugging and attach the debugger to localhost:1044.

like image 28
Samuel Yung Avatar answered Nov 13 '22 14:11

Samuel Yung