Monday, February 21, 2011

Maven war overlay and debugging

I'm currently working on a project which uses the maven war overlay feature. In such condition, I didn't succeed to start my a Tomcat instance from Eclipse WTP. That's because the war is built to late in the maven process and the Maven integration with WTP never calls the appropriate building step. Thus, I decided to start my server from the command line. With 'war overlay', I need to do :

mvn tomcat:run-war

But, what about debugging? Here I found two solutions.

Solution 1 : the standard mode

Just use :

mvnDebug tomcat:run-war

But it's a pre-configured solution and you should want to precise some specific options according to your environment.

Solution 2 : customize your debugging options

This is very simple.
  • Ensure that you correctly declared your JAVA_HOME
  • Set the debugging options which will be used by the JVM

For example :
export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"

Then, just start your server with mvn tomcat:run-war

3 comments:

Sébastien Lorber said...

And don't forget to connect with remote debugging eclipse configuration, or your server won't start because of the suspend=y


Note you can also debug tests executed with maven surfire with the same kind of trick, just adding:
-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5000 -Xnoagent -Djava.compiler=NONE"

Here the suspend=y is more useful because since tests could be finished before you connected

Javin @ FIX Protocol Tutorials said...

Nice article , just to add I would suggest start up script to put JVM debug parameter and use a variable e.g. isDebugEnabled and also REMOTE_DEBUG_PORT in the script and export this variable when you want to remote debug your Java application. This will be very handy and will require just one time setup work.

Thanks
Javin
How to setup remote debugging in Eclipse

Rahul said...

Thanks for the great information in your blog Selenium Training in Chennai