0

I have a standalone maven project where I run a java program using org.codehaus.mojo exec plugin.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>java</executable>   
                    <argument>-classpath</argument>
                    <classpath>
                    </classpath>
                    <argument>com.abc.Main</argument>
                </arguments>
            </configuration>
        </plugin>

I also have test cases under src/test/java directory, which I can debug using surefire plugin. But, I can't debug the main code using mvnDebug directly by running com.abc.Main class(though this looks straightforward by attaching Eclipse workspace project in Debug mode on a port being listened by mvnDebug). I'm wondering if we can use surefire plugin directly on main code to debug?

UPDATED

I use eclipse Kepler version with installed "Maven Integration for Eclipse" plugin

IndoKnight
  • 1,846
  • 1
  • 21
  • 29
  • Usually, you know you're not doing a good job explaining and illustrating your problem when nobody replies... Show some code, draw a picture, explain a bit more about your problem. I also have a problem: some of my code doesn't do what I expect. Do you know what's wrong? :) – carlspring Oct 21 '13 at 16:30
  • Okay, I updated this as you suggested. Yes, I do know what's wrong, that's why I'm here on this site :) – IndoKnight Oct 29 '13 at 17:01

1 Answers1

2

Try running Maven like this:

mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9001 -Xnoagent" clean install

And use the remote debugger to connect to port 9001. This will allow you to put breakpoints in your test code.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • Thanks, here your command runs the test case classes, which I do not want. I want to run just the main program in debug mode. I tried your command by replacing "clean install" with "exec:exec". It just ran my program without debugging it. With your command I can debug my main source code "through" test cases as starting point, which I already know and mentioned in my post. – IndoKnight Oct 29 '13 at 18:57
  • In that case try debugging the `exec:exec` by passing in the JVM debugging options described here: http://stackoverflow.com/questions/2935375/debugging-in-maven. – carlspring Oct 30 '13 at 00:37