Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Maven User
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h1>Introduction</h1> <p><span style="color: rgb(0,0,0);">There are two ways to use Maven and</span> <span style="color: rgb(0,0,0);"><a href="http://www.eclipse.org">Eclipse</a></span> <span style="color: rgb(0,0,0);">:</span></p> <p>1. Use Eclipse as the editor, and Maven command line for commands, or</p> <p>2. Using an Eclipse plugin for Maven (see <a class="confluence-link" href="/display/MAVENUSER/Eclipse+Integration" data-linked-resource-id="77995" data-linked-resource-type="page" data-linked-resource-default-alias="Eclipse Integration" data-base-url="http://docs.codehaus.org">Eclipse Integration</a> )</p> <p>Use the first one if you're much more comfortable with using the command line for your Maven tasks, but would like to take advantage of Eclipse' features ( code complete, refactoring, etc ). Use the second one if you want Eclipse to handle all these things - creation to editing to execution.</p> <p>For this page, we will discuss the Eclipse plugin for Maven </p> <h2>Setting up</h2> <p> To do so, you must install an Eclipse plugin for maven, see <a class="confluence-link" href="/display/MAVENUSER/Eclipse+Integration" data-linked-resource-id="77995" data-linked-resource-type="page" data-linked-resource-default-alias="Eclipse Integration" data-base-url="http://docs.codehaus.org">Eclipse Integration</a>.</p> <h1>Debugging your Maven Project in Eclipse</h1> <p>Note that there are two debug modes in maven: the <strong>Generic</strong> and the <strong>Surefire</strong>. If you want to debug maven itself, one of maven's plugins, or a maven project, use the <strong>Generic</strong> Approach. If you want to debug a test in your project launched by surefire, use the <strong>Surefire</strong> Approach.</p> <p>Most likely, you're debugging your test so try the <strong>Surefire</strong> Approach. The <strong>Generic</strong> Approach is more for maven & maven plugin developers.</p> <h2>Setting up Eclipse</h2> <h3>Create a Java Project for the Maven Debug session</h3> <p>Create a new Java Project and call it "Maven Debug". This Project will <strong>never</strong> have any source code in it, it is just a shell for attaching the debugger.</p> <h3>Create Remote Java Application Debug Configurations</h3> <p>Create two debug configurations, one for Generic debugging called "Maven" and one for Surefire debugging called "Maven Surefire"</p> <p><code>Run</code> > <code>Debug...</code> and then right click on <code>Remote Java Application</code> and chose <code>New Launch Configuration</code>.</p> <p>On the <code>Connect</code> tab click the <code>Browse...</code> button and select the "Maven Debug" project. Make sure that the <code>Connection Properties</code> > <code>Port</code> is 8000. (This matches the address value set on the MAVEN_OPTS command line in the mvn-debug.bat file from above)</p> <p>On the <code>Source</code> tab click <code>Add...</code> and select all projects that have any Maven source that you want to debug.</p> <p>Now do the same thing to create a second Remote Java Application called "Maven Surefire" with a port of 5005.</p> <h2>Surefire Debugging</h2> <p>Select break points in the code you're are going to run.</p> <p>From your command line, append the following to your maven command. <br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>-Dmaven.surefire.debug </pre></td></tr></table> <p><br class="atl-forced-newline" /> For example, to debug the tests run by the Maven lifecycle <code>install</code>, do <code>mvn install -Dmaven.surefire.debug</code></p> <p>Wait for Maven to pause its execution and display the message, <br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>Listening for transport dt_socket at address: 5005 </pre></td></tr></table> <p><br class="atl-forced-newline" /> Attach the debugger to the running maven by selecting the "Maven Surefire" debug configuration created above.</p> <h2>Generic Debugging</h2> <p>Select break points in the code you're are going to run.</p> <p>Run Maven in debug mode, e.g <code>mvn-debug install</code></p> <p>Attach the debugger to the running maven by selecting the "Maven" debug configuration created above.</p> <p>Eclipse will now stop Maven at the breakpoints you have enabled.</p> <h2>Setting up Maven 2.0.8+</h2> <p><strong>Note:</strong> If you are using Maven 2.0.8 or newer, simply run the "mvnDebug" command in place of "mvn" and skip down to setting up Eclipse.</p> <h2>Setting up Maven <2.0.8</h2> <p>Open <code>%M2_HOME%/bin/mvn.bat</code></p> <p>At line 30, you'll find this, <br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 </pre></td></tr></table> <p><br class="atl-forced-newline" /> <br class="atl-forced-newline" /> Uncommenting the line by deleting <code>@REM</code></p> <p>Also add</p> <table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>set MAVEN_OPTS= </pre></td></tr></table> <p>in the :end section, otherwise the debug will be turned on even when you run the normal mvn.bat </p> <p>Save that file as <code>mvn-debug.bat</code> (or any convenient name you may want). You now have two Maven batch files, one for normal use, and one for debugging.</p> <p>Now when you want to debug maven, run <code>mvn-debug</code> instead of <code>mvn</code> (i.e. instead of <code>mvn install</code>, use <code>mvn-debug install</code>) <br class="atl-forced-newline" /></p> <h2>Trouble Shooting Debugging</h2> <h3>Source not found</h3> <p>I "stepped" into a code block and instead of the source I get "Source not found" with an "Edit Source Lookup Path..." button</p> <p>This occurs because you do not have a project that contains the source for this class. You will need to checkout the source from the Maven subversion repository and then update the source path of the "Maven Debug" project to include this new project.</p> <p>First you need to locate which project in the repository the class file belongs to.<br /> Chances are this class exists on your classpath for a project. Select from the menu "Navigate > Open Type..." and enter the name of the class that is missing. In the matching types list select the correct class and click OK.</p> <p>Ensure "Link with Editor" is enabled in your "Package Explorer". With the missing file selected the Package Explorer should have opened the class from a jar file from the classpath of a project. The name of the jar file should help in locating the project in the Maven subversion repository. The SCM location is also contained in the <code>pom.xml</code> file in the jar, this file is located at <code>META-INF/groupdId/artifactId/pom.xml</code>. E.g for the missing file "MavenArchiver.class" this file is contained in "maven-archiver-2.2.jar" and the pom.xml file in "META-INF.maven.org.apache.maven.maven-archiver" lists the SCM connection as "scm:svn:<a href="https://svn.apache.org/repos/asf/maven/shared/tags/maven-archiver-2.2">https://svn.apache.org/repos/asf/maven/shared/tags/maven-archiver-2.2</a>".</p> <p>Checking out the maven project you need and then run <code>mvn eclipse:eclipse</code>.</p> <p>From the editor with the missing source, click on "Edit Source Lookup Path..." > "Add..." > "Java Project" > "OK" and select the newly checked out maven project.</p> <h3>The source does not match the debug stack trace</h3> <p>It is more than likely that you have a different version on your source path than the one in use by Maven.</p> <p>The only way to fix this problem is to have matching versions of source to java class files.<br /> This may require checking out the correctly tagged version of the plugin.</p> <p>However there is no way to determine which version Maven is using as this is handled by the Plexus classworld's class loader.</p> <h1>Debugging Maven Core with Eclipse</h1> <p>See <a href="http://www.nabble.com/forum/ViewPost.jtp?post=8988667&framed=y&skin=177">Re: debugging maven with eclipse written by John J. Franey</a> for some setup guidance. Those instructions should be merged into here at some stage.</p> <h1>FAQ</h1> <p> Question:</p> <p> 1. Why can't I just use Generic Debugging even for my tests?</p> <p> Answer:</p> <p> 1. Because maven-surefire-plugin forks a new JVM by default, thus, the your MAVEN_OPTS are not passed. There are three fork modes of maven-surefire-plugin: Once (default), Never, and Always. For Once mode, surefire will run another JVM and will do all its testing there. For Never, it will use the same JVM instance as that of maven (this is normally not use so that you can isolate your tests). But if you really want to isolate your tests, run in Always mode. This will run a new JVM instance for every test sets it runs.</p> <p> Question:</p> <p> 2. Will using argLine parameter of maven-surefire-plugin work instead of the -Dmaven.surefire.debug ? </p> <p> Answer:</p> <p> 2. Yes. maven.surefire.debug acts like a shorthand version of argeLine=<debugging configuration>. So in most cases, using maven.surefire.debug be enough.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced