1

I have a Maven project in eclipse, which I run with a Run configuration. That configuration does compile and exec:exec with a script (called runner) defined in my pom.xml dependent on the OS (.bat in Windows, .sh in Linux). The runners do OS-dependent stuff and then start Java with my application. Which runner to use is specified with profiles like the following:

<profile>
    <id>WINused</id>
        <activation>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <properties>
            <runnerForLaunch>${basedir}/src/runners/windowsRunner.bat</runnerToUse>
        </properties>
    </profile>

So, when I want to run it, I use Alt+Shift+X, M and select the Maven config. Later, I just use Ctrl+F11.

When I have to debug it, I have to do the following:

  1. Edit the pom.xml to use another runner script that adds -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y to the Java call.
  2. Launch the run configuration.
  3. Launch a debug configuration that connects to the debugger.

My question is, can I somehow shorten that process? I regularly forget to undo my changes to pom.xml and use the runner I currently do not need. Can't Maven somehow detect if I run it with Run as or Debug as and adjust variables depending on that?

Bowi
  • 1,378
  • 19
  • 33

2 Answers2

1

If the runner config in your POM supports command line arguments:

  • Create another profile containing:

    <profile>
      <id>debug</id>
      <properties>
        <debugArgument>-agentlib: ...</debugArgument>
      </properties>
    </profile>
    
  • Use the new property in:

    <runnerForLaunch>${basedir}/src/runners/windowsRunner.bat ${debugArgument}</runnerToUse>
    
  • Add debug to Profiles: in your debug configuration.

  • Use %1 or $1 at the Java call in your scripts.

Or:

  • Declare and supply a property value of <debugArgument>debug</debugArgument>.
  • Evaluate %1 or $1 in your scripts and call Java with different arguments accordingly.

Or:

  • Add a property debugArgument with 1) debug or 2) -agentlib: ... to Parameter Name / Value in your debug configuration.
  • Use the property in:

    <runnerForLaunch>${basedir}/src/runners/windowsRunner.bat ${debugArgument}</runnerToUse>
    
  • 1) Evaluate %1 or $1 for debug and call Java with different arguments accordingly or 2) use them at the Java call in your scripts.
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • So you basically say that I should have a run configuration and a debug configuration? That could shorten the process a bit, but unfortunately Eclipse's `Ctrl+F11` / `F11` do always run the last recently used configuration. It doesn't differentiate that `Ctrl+F11` runs the last recently used *run* configuration and `F11` the last *debug* configuration. – Bowi Feb 27 '17 at 09:11
  • @Bowi Sadly, that's true. It's because there aren't two different types of run/debug configurations. The according toolbar drop-downs are just Favorites views. `F11` just switches to the Debug view if a breakpoint is reached. – Gerold Broser Feb 27 '17 at 11:36
  • And there is no way for a xy configuration to determine if it has been started using *run* or *debug*? – Bowi Feb 27 '17 at 12:23
  • 1
    @Bowi Not that I'm aware of. But see [Assigning a keyboard shortcut for a specific Eclipse build configuration](http://stackoverflow.com/q/1437323/1744774) and also [Eclipse - Adding Java 'Application Run' Shortcuts to toolbar](http://superuser.com/q/57352/516482). – Gerold Broser Feb 27 '17 at 14:19
0

Usually, you don't need to add debug options because eclipse simply adds them by calling "mvnDebug" instead of "mvn" when debugging a maven project. I suggest you simply run the shell script before you run your Java app, and start the Java app using exec:java in order to have it run inside the maven process that is attached to the eclipse debugger.

user1050755
  • 11,218
  • 4
  • 45
  • 56