Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Dealing with Eclipse-based IDE

Table of Contents

  1. Introduction
  2. Openning your Maven Project in Eclipse
  3. Running your Maven Project in Eclipse
  4. Debugging your Maven Project in Eclipse
    1. Generic Debugging
    2. Surefire Debugging

Introduction

TODO

Openning your Maven Project in Eclipse

TODO

Running your Maven Project in Eclipse

TODO

Debugging your Maven Project in Eclipse

Note that there two debug modes in maven: the Generic, and the Surefire. If you want to debug maven itself, or a maven project of yours, use the Generic Approach. If you want to debug a test in your maven project launched by surefire, use the Surefire Approach.

Generic Debugging

  1. Setting up Maven
    1. Open %M2_HOME%/bin/mvn.bat
    2. At line 30, you'll find this,
      . Delete @REM (Thus, uncommenting that line)
    3. Save that file as mvn-dbg.bat (or any convinient name you may want). You now have to maven batch files, one for normal use, and one for debugging.
    4. Run your maven command but use mvn-dbg instead of mvn (i.e. instead of mvn install, use mvn-dbg install)
  2. From your Eclipse,
    1. Select break points in the code you're running.
    2. Run > Debug > Remote Java Application > New Launch Configuration
    3. For the Project field, select your maven project, and
    4. For the Port, set it to 8000 (8000 is the default port for the Generic Maven Debugging. But you can modify it by changing the address field shown in Generic Debugging - 1.2)
    5. Press Debug button to start debugging

Surefire Debugging

  1. From your command line,
    1. Append the following to your maven command.
      For example, to debug the tests ran by the maven lifecycle install, do mvn install -Dmaven.surefire.debug
    2. Wait for your maven to pause its execution and display the message,
  2. From your Eclipse,
    1. Select break points in the code you're running.
    2. Run > Debug > Remote Java Application > New Launch Configuration
    3. For the Project field, select your maven project, and
    4. For the Port, set it to 5005
    5. Press Debug button to start debugging

FAQ

 Question:

    1. Why can't I just use Generic Debugging even for my tests?

 Answer:

    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 isloate your tests, run in Always mode. This will run a new JVM instance for every test sets it runs.

Question:

    2. Will using argLine parameter of maven-surefire-plugin work instead of the -Dmaven.surefire.debug ? 

 Answer:

    2. Yes. maven.surefire.debug acts like a shorthand version of argeLine=<debugging configuration>. So in most cases, using maven.surefire.debug be enough.

  • No labels