1

Let me start by clarifying I have check every possible resource, tutorial, video, other stackoverflow questions that I could get my hands on that are related in order to try and find an answer to this. I'm using java 8 and Eclipse Luna Service Release 2 (4.4.2) with m2e plugin, It's quite hard to believe but it seems there isn't a single example that clearly explains how you actually debug a Maven Java application USING ECLIPSE. There are no less than 40 different sources here are some

What I'm trying to do is click the debug button in eclipse and run a debug configuration that allows me to hit my breakpoints.

I have the following configuration in Eclipse

enter image description here

this runs the exec:exec goal from my pom.xml which looks like this

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-classpath</argument>
                        <classpath />
                        <argument>core.app.server</argument>
                        <argument>-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=*:49875 </argument>
                    </arguments>
                    <workingDirectory>${project.build.outputDirectory}</workingDirectory>
                </configuration>
            </plugin>

Ok, so far so good. At this point if I run the debug configuration the app launches and then hangs which I'm assuming it is waiting for the debugger to remotely connect based on the arguments in my pom.xml. So the app starts hangs and in Eclipse at this point I'm looking at this

At this point I've tried everything I can imagine. I notice the exec plugin launcher starts on a random port which in the picture is 51661, when in my exec arguments in the pom.xml I have it set to 49875 so this seems off. Another thing I noticed if I removed the <argument>-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=*:49875 </argument> line from my pom.xml the app launches completely , runs fine but this gets me no where. I have tried to connect using a "Remote Java Application" configuration after the app launches this also does not work. I normally use IntelliJ which makes it an absolute breeze since everything is handled OOTB, unfortunately I have to get this working in Eclipse as well in a similar fashion.

How do I configure the Debug Configuration in a way that will allow me to launch the app and hit my breakpoints?

EDIT 1 When setting suspend=n the app still hangs when launching with the argument agentlib:jdwp

EDIT 2 In an effort to get this figured out without wasting another day on something that should be effortless, I tested running a clean install from and debug configuration and then tested using the run as commands provided by m2e shown below and the m2e commands work perfectly where as the same exact commands ran with a debug configuration fail for missing references.

EDIT 3 Reading the documentation on the exec maven plugin here https://www.mojohaus.org/exec-maven-plugin/index.html it says the difference between exec:exec and exec:java is that the ladder execute programs and Java programs in a separate process and the former execute Java programs in the same VM. I think this might be somewhat related to the issue I'm having. This should be really easy to test for someone familiar with MAven/Eclipse I would think, is anyone able to create a super basic hello world app maven project and see if they can set and hit a break point in the main method, should take but 5-10 min?

After_Sunset
  • 674
  • 3
  • 10
  • 25
  • "hanging" is a good sign: process waits for a debug client to attach (you chose `suspend=y`;) – xerx593 Sep 08 '22 at 19:35
  • The wrong port can be explained by bad syntax (address expects a port only, no wildcards, no host name...) better: `address=49875`.. – xerx593 Sep 08 '22 at 19:37
  • @xerx593 changing the address to the format you suggest seems to have no impact. exec plugin still launches on a random port. This seems intended, which is one point of confusion I'm not sure how the two ports are related if at all. – After_Sunset Sep 08 '22 at 19:43
  • Isn't this automatic when using current releases of Java, Eclipse, Maven, and M2E? – nitind Sep 08 '22 at 21:25
  • Isn't what automatic, the debugging process? You would think so. It is definitely not automatic in the version I'm using and it seems to be a newer release. – After_Sunset Sep 08 '22 at 21:44
  • Eclipse Luna is 8 years and 20 releases behind. It's a bit strange that you complaining about such old things. As shown in my video whose collections of links you reference in your question, it works differently and requires a more recent Eclipse version than you have: https://youtu.be/GnNnQY5ujFg?t=412 – howlger Sep 09 '22 at 06:23
  • 1
    False. Current Eclipse version supports Java 8 and much older Java versions. What is the reason to run/debug it via Maven (which is slow) instead of directly (which would be faster)? Please improve your question by focusing it on your problem (tl;dr). – howlger Sep 09 '22 at 12:20
  • 1
    The current version of Eclipse requires at least Java 11 for itself, but it can run programs using any release of Java. You tell Eclipse about available versions of Java in the Preferences (Java > Installed JREs) – greg-449 Sep 09 '22 at 13:11
  • Since it's hanging, it seems the breakpoint is being hit. Sometimes this happens to me but the Debug view does not get activated automatically. If you open the debug view after the hand, is the breakpoint stoped there? – Romulo Diniz Sep 09 '22 at 18:44

1 Answers1

0

I got it working like so:

  • Download, extract (latest!?) Luna SR2 JavaEE Edition
  • set (correct) JAVA_HOME/vm in eclipse.ini (oracle-8 latest)
  • Welcome Screen, create new Maven project, simple, skip achetype...

(So with fresh defaults, simple project):

With the following pom section :

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
        <execution>
          <goals>
            <goal>exec</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <executable>C:\Program Files\Java\jdk1.8.0_333\bin\java.exe</executable>
        <arguments>
          <argument>-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=49875</argument>
          <argument>-classpath</argument>
          <classpath />
          <argument>com.example.Demo</argument>
        </arguments>
      <workingDirectory>${project.build.outputDirectory</workingDirectory>
      </configuration>
    </plugin>
  </plugins>
</build>

(very similar to yours, only significant difference: address, server is crucial in this approach, suspend either)

With the same (Maven) Run configuration, as you show:

We now additionally need:

  • "Debug Configurations..."
  • Remote Java Application(! ..because we chose "server"..)
  • we select the (sources) project as "Project"
  • Connection Type: attach
  • Host: localhost
  • Port: the one configured in jdwp

Looks like:

run config 2

  1. Set "my" breakpoint in:
package com.example;

public class Demo {

    public static void main(String[] args) {
        int x = 0;
        x++; // just to set breakpoint somewhere
        System.out.println(x);
    }

}
  1. "Run" "Exec_Java" (suspend, and server flags (and all) have effect!)

  2. Console(Exec_Java) should report:

    ...
    [INFO] --- exec-maven-plugin:3.0.0:exec (default-cli) @ luna-res ---
    Listening for transport dt_socket at address: 49875   //!!
    
  3. "Debug" "New_Configuration".

..and the breakpoint halts(, and we get the "switch perspective dialog";)

success

xerx593
  • 12,237
  • 5
  • 33
  • 64
  • 1
    Thanks for this it is very appreciated. Will run through it and mark as correct when I can confirm. Thanks again – After_Sunset Sep 10 '22 at 12:43
  • Key point/drawback: you need to run *two* configurations (simultaneously...older/ other language developers: don't know it different) 1. The jdwp server (I used (almost) identical config as yours). And, 2., a "client", which can attach to that ("Debug Remote Java Application" in our scenario;) – xerx593 Sep 10 '22 at 15:37
  • Wow, this is the most cumbersome way to locally debug a Java application in Eclipse that I have ever seen. I thought the questioner already noticed their mistake and just forgot to delete the question. – howlger Sep 10 '22 at 16:43
  • @howlger lol what a crybaby. The same question has been asked extensively across forums, based on that your argument is already lost. The fact the method exists is proof enough it is useful at the very least for certain things. – After_Sunset Sep 10 '22 at 22:07