开发者

Debug a maven plugin's execution in a maven web-project

Is there any way to actually debug a maven plugin while it is in action. What I mean is that for example we have the maven-clean-plugin. So when this plugin executes it's action can we somehow debug and check inside the source code of maven-clean-plugin?

Obviously we would have to associate the Java sou开发者_如何学Pythonrce for the plugin in eclipse but how can we set it for debugging?

Thanks.

EDIT: Changing the subject I'm sorry guys maybe I should have been more precise. Actually I have my web-app which is a maven project, which makes use of 3rd party maven plugins. Now when I do a mvn clean install I need to debug my 3rd party maven plugin. Now in my maven dependency I dont get a dependency to that plugin jar, which is quite normal. Any ideas?


If you are using Eclipse with the m2eclipse plugin, simply launch your build with Debug As... instead of Run as....

If you are not using m2eclipse, run mvnDebug instead of mvn (for Maven 2.0.8+) and attach a remote debugger on port 8000. For Maven 2.0.8<, add the remote debuggin options to the start script.

Of course, you need to import the sources of the plugin in your workspace.

See also

  • Developing and debugging Maven plugins
  • Dealing with Eclipse-based IDE


If you want to debug Maven execution in eclipse, here is how I did it, with mostly command-line tools (no Eclipse plugin used) (may be off at some points, I haven't done that for 6 months):

  • Run, from the command line, mvndebug in place of the mvn command. Maven will begin launching and wait for an external debugger to appear on a TCP port before resuming. Note the port number.
  • Configure in Eclipse a custom, remote debug configuration. (See http://www.ibm.com/developerworks/library/os-ecbug/ , Remote debugging) - set the port number as the one used by mvndebug. Also put the source files that you will be using for debugging in the Debug configuration.
  • Launch the remote debug configuration. Maven should resume and you will catch bugs in Eclipse.


This might be slightly off, since I'm going to talk about IntelliJ IDEA. With IDEA, you can load a maven project directly, and then simply right click on one of the build lifecycle phases (clean, package, install etc...) and choose debug. The IDE then runs that phase with the correct classpath and drops you into a debugger.

I've used the debugger to debug several of my own plugins. I've never tried debugging a third party plugin, although I imagine this will be relatively painless if the jar still has debug symbols in it and you have corresponding source code.

The community edition of IDEA is available for no fee.


Just replace mvn with mvnDebug in your command:

mvnDebug clean install

As result JVM listens for debugger at port 8000. For finer control you can set MAVEN_OPTS environment variable with standard JVM debug parameters:

export MAVEN_OPTS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
mvn clean install


In NetBeans 7.4, Right-click the project > Properties > Actions. Pick the Build project action (or any other), then next to "Set Properties" click Add and Debug Maven Build.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜