[英]How debug web application with maven Eclipse and glassfish?
[英]How to debug a Maven application in Eclipse
让我首先澄清一下,我已经检查了所有可能的资源、教程、视频和其他我可以得到的相关的 stackoverflow 问题,以便尝试找到答案。 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. 这里有不少于 40 个不同的来源
我想要做的是单击 eclipse 中的调试按钮并运行允许我命中断点的调试配置。
我在Eclipse中有如下配置
这从我的 pom.xml 运行 exec:exec 目标,看起来像这样
<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>
好的,到目前为止一切顺利。 此时,如果我运行调试配置,应用程序启动然后挂起,我假设它正在等待调试器基于我的 pom.xml 中的 arguments 远程连接。 所以应用程序开始挂起,此时我正在查看 Eclipse
在这一点上,我已经尝试了我能想象到的一切。 我注意到 exec 插件启动器在图片中为 51661 的随机端口上启动,当我在 pom.xml 中的我的 exec arguments 中将其设置为 49875 所以这似乎关闭了。 如果我从我的 pom.xml 中删除了<argument>-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=*:49875 </argument>
行,我注意到的另一件事是应用程序完全启动,运行良好但这让我无处可去。 在应用程序启动后,我尝试使用“远程 Java 应用程序”配置进行连接,这也不起作用。 我通常使用 IntelliJ,这让它变得轻而易举,因为一切都是 OOTB 处理的,不幸的是,我必须以类似的方式在 Eclipse 中让它工作。
如何以允许我启动应用程序并命中断点的方式配置调试配置?
编辑 1当设置suspend=n
时,应用程序在使用参数agentlib:jdwp
启动时仍然挂起
编辑 2为了在不费力的情况下再浪费一天的时间弄清楚这一点,我测试了运行clean install
和调试配置,然后使用如下所示的 m2e 提供的命令运行测试,m2e 命令完美运行由于缺少引用,使用调试配置运行相同的确切命令失败。
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程序在一个单独的进程中,前者在同一 VM 中执行 Java 程序。 我认为这可能与我遇到的问题有关。 对于熟悉 MAven/Eclipse 的人来说,这应该很容易测试我认为,是否有人能够创建一个超级基本的 hello world 应用程序 maven 项目,看看他们是否可以在主要方法中设置并达到断点,应该采取但5-10 分钟?
我让它像这样工作:
JAVA_HOME
/ vm
(oracle-8 最新)(所以使用新的默认值,简单的项目):
使用以下 pom 部分:
<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>
(与您的非常相似,只有显着区别: address
, server
在这种方法中至关重要,也可以suspend
)
使用相同的(Maven)运行配置,如您所示:
我们现在还需要:
好像:
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);
}
}
“运行”“Exec_Java”(挂起和服务器标志(和所有)都有效!)
Console(Exec_Java) 应该报告:
... [INFO] --- exec-maven-plugin:3.0.0:exec (default-cli) @ luna-res --- Listening for transport dt_socket at address: 49875 //!!
“调试”“New_Configuration”。
..和断点停止(,我们得到“切换透视对话框”;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.