Issue
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
- Debugging with exec-maven-plugin
- https://blog.jooq.org/how-to-debug-your-maven-build-with-eclipse/
- Eclipse not stopping at java breakpoints during remote debug
- https://github.com/howlger/Eclipse-IDE-improvements-videos/tree/2022-03/sample_code
- IntelliJ IDEA Maven project StackOverflowError when running debug configuration
- Debugging in Maven?
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
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?
Solution
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:
- 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);
}
}
"Run" "Exec_Java" (suspend, and server flags (and all) have effect!)
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 //!!
"Debug" "New_Configuration".
..and the breakpoint halts(, and we get the "switch perspective dialog";)
Answered By - xerx593
Answer Checked By - Terry (JavaFixing Volunteer)