27

I'm using maven / surefire / eclipse to write some code and later test / debug it.

Standard way to do it is by using maven.surefire.debug maven property. By default, when this property is enabled, maven starts listening on port 5005 and I can attach to the debugged process using remote debugger. When the test finishes remote debugger disconnects from the server.

This process involves two steps when done using in eclipse:

  1. Run maven
  2. Connect using remote launch configuration

What I would like to achieve is to reduce this to:

  1. Run maven

I have found, that setting the maven.surefire.debug property to some remote debug options will change the remote debug behaviour. Thus when I specify i.e.

-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=5005"

then build will try to connect to my eclipse process listening on port 5005. This way I invert the default client/server roles of maven and eclipse.

However there is one big problem with this approach. It doesn't give me anything, as after maven build finishes, eclipse stops listening on server port. This is the part that I don't understand. When I connect as debug client from eclipse to for example WebLogic server, it allows me to connect / disconnect freely as many times as I want.

Anyone knows if this is normal, or maybe I need to specify some additional options to make debugging maven tests easier?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
mateusz.fiolka
  • 3,032
  • 2
  • 23
  • 24
  • 1
    This is correct behavior. WebSphere is a server so it listens to debugger continuously. Tests run and at certain moment finishes their execution (together with maven session). You can also disconnect and connect to the Maven many times but only as long as tests execution last. – Henryk Konsek Sep 24 '10 at 18:01
  • @Henryk Konsek - This is why I wanted to make eclipse the server, and test engine the connect to it. – mateusz.fiolka Sep 24 '10 at 18:51

4 Answers4

23

Simple way:

1. Open the Debug As > .. dialogue box
2. In the goal text box, give
     -DforkMode=never test
3. Run the debug project
Zeba Ahmad
  • 246
  • 2
  • 2
  • 1
    I accept this answer, although this method comes with a risk (as explained here: http://stackoverflow.com/questions/3185850/maven-surefire-plugin-fork-mode). Debugging this way running classes will share classpath with Maven which may cause some problems. – mateusz.fiolka Jul 04 '12 at 06:56
  • "[WARNING] The parameter forkMode is deprecated since version 2.14. Use forkCount and reuseForks instead". This is what maven says nowadays. – Lluís Suñol May 05 '17 at 10:41
22

Bit late in contributing but thought it was worthwhile still.

In Eclipse debug configuration, create "Maven build" debug config:

Goals = -Dmaven.surefire.debug test

Profiles = myconfigprofile,weblogic

or for a specific TestSuite:

Goals = -Dmaven.surefire.debug -Dtest=com.myorg.mypkg/MyTestSuite.java test

Profiles = myconfigprofile,weblogic

N.B. Don't put the props in "JRE/jvm arguments" as this doesn't seem to pause

Create additional "Remote Java Application" config:

Host = localhost

Port = 5005

Running/ debugging your mvn build will stop and listen on 5005 by default.

Starting your remote debug config will attach.

See also: http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html

Ravindranath Akila
  • 209
  • 3
  • 35
  • 45
wmorrison365
  • 5,995
  • 2
  • 27
  • 40
2

If you're using m2eclipse, why not simply right-click then Debug > Maven test?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 1
    I have tried, but it doesn't do anything. Do I need anything to configure it? – mateusz.fiolka Sep 24 '10 at 18:47
  • 3
    On the other hand "debug as junit test" works fine. Actualy this is enough fo me. – mateusz.fiolka Sep 24 '10 at 18:50
  • 1
    Debug > Maven test really doesn't do anything. The mateusz.fiolka's way seems to be the only one working for me and running test and then launch remote debugger is really annoying – lisak Dec 09 '10 at 19:00
0

if you are using Maven 2.0.8+, then it will be very simple,

Please refer my answer.

Maven build debug in Eclipse

Community
  • 1
  • 1
Rajesh
  • 1,911
  • 1
  • 22
  • 19