mir*_*lon 18 java debugging breakpoints intellij-idea maven
我在System.out.println("test")命令行上有一个断点.我相信命令是通过执行来达到的,因为我看到打印的字符串"test".但断点被忽略了.
断点始终是一个红色圆圈,没有勾或十字.我认为这是一个问题,当IDEA认为该类未加载时,因为该命令已执行.
我可以在各种情况下重现它:
当我按下调试(使用maven配置install exec:exec -DforkMode=never)
远程调试 - 我在控制台中以调试模式运行maven目标:
mvnDebug install exec:exec -DforkMode=never
要么
mvnDebug install exec:exec
IDEA中的远程调试配置:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000在这两种情况下,调试器只打印"连接到目标VM,地址:'localhost:8000',传输:'socket'"
我也试过File > Invalidate Caches / Restart
并清理构建,但断点仍然被忽略.
组态:
Ubuntu 13.10
IntelliJ IDEA Ultimate build 133.944
Apache Maven 3.0.4
Java版本:1.7.0_51,供应商:Oracle Corporation
操作系统名称:"linux",版本:"3.11.0-17-generic",arch:"amd64",family: "UNIX"
编辑:pom.xml的相关部分:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-D--secret--.server.configuration=/usr/local/etc</argument>
<argument>-classpath</argument><classpath/>
<argument>com.--secret--.Server</argument>
</arguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我的解决方案
考虑到您有一个依赖于系统属性的程序:
package com.mycompany.app;
public class App {
private static final String GREETING = System.getProperty("greeting", "Hi");
public static void main(String[] args) {
int x = 10;
System.out.println(GREETING);
}
}
Run Code Online (Sandbox Code Playgroud)
你正在运行它exec:exec:
mvn exec:exec -Dexec.executable=java "-Dexec.args=-classpath %classpath -Dgreeting=\"Hello\" com.mycompany.app.App"
Run Code Online (Sandbox Code Playgroud)
通过一些"初始魔法",我们可以调试Maven启动的过程exec:exec.
更改exec:exec目标以启用远程调试.我使用suspend=y和server=n,但随时配置JDWP代理,请你:
-agentlib:jdwp=transport=dt_socket,server=n,address=127.0.0.1:8000,suspend=y
这不会直接传递给maven JVM,而是传递给exec.args将用于exec:exec:
mvn exec:exec -Dexec.executable=java "-Dexec.args=-classpath %classpath -agentlib:jdwp=transport=dt_socket,server=n,address=127.0.0.1:8000,suspend=y -Dgreeting=\"Hello\" com.mycompany.app.App"
Run Code Online (Sandbox Code Playgroud)
创建Remote配置(我再次使用Listen策略.您应该根据您的流程设置进行调整):
现在切换断点并调试远程配置.使用上面的设置,它将等到您的过程开始:
最后运行exec:exec上面的行并随意调试你的应用程序:
所以基本上你需要两个"运行/调试"配置才能工作:
| 归档时间: |
|
| 查看次数: |
36425 次 |
| 最近记录: |