Java Eclipse - 调试器不会在断点处停止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1370868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 11:15:56  来源:igfitidea点击:

Eclipse - debugger doesn't stop at breakpoint

javaeclipsedebuggingjunit

提问by Roy

I am trying to trouble shoot a JUnit. In the source code, I have set break point in two places: 1) in a line where a static member is initialized 2) the first line of one of the test cases.

我正在尝试解决 JUnit 问题。在源代码中,我在两个地方设置了断点:1) 在初始化静态成员的行中 2) 一个测试用例的第一行。

The debugger stops in the static field initializing line. But it doesn't stop in the test case. No matter where I set the break point in the test case, the debugger doesn't stop there. I know for sure that the test case is executed as I can see the log messages that I have added appear in the log.

调试器在静态字段初始化行中停止。但它并没有停止在测试用例中。无论我在测试用例中的何处设置断点,调试器都不会停在那里。我确信测试用例已执行,因为我可以看到我添加的日志消息出现在日志中。

Any help would be greatly appreciated.

任何帮助将不胜感激。

I am using Eclipse Galileo and JUnit4 launcher.

我正在使用 Eclipse Galileo 和 JUnit4 启动器。

采纳答案by Vineet Reynolds

This could be related to one of the bugs in JDK 6 Update 14, as indicated in the release notes for JDK 6 update 15.

这可能与JDK 6 Update 14中的错误之一有关,如 JDK 6 update 15 的发行说明中所示

If this indeed turns out to be the issue, you should move to a higher version of the JDK (that's no guarantee though, since fixes have been released against 6u16, 6u18 and 7b1). The best bet is to use -XX:+UseParallelGC flag. Increasing the size of the minimum and maximum heap size, to delay the first GC, bring temporary relief.

如果这确实是问题所在,那么您应该转向更高版本的 JDK(但这并不能保证,因为已经针对 6u16、6u18 和 7b1 发布了修复程序)。最好的办法是使用 -XX:+UseParallelGC 标志。增加最小和最大堆大小,延迟第一次GC,带来暂时的缓解。

By the way, use this bug report in Eclipseto track how others have been faring.

顺便说一下,在 Eclipse 中使用这个错误报告来跟踪其他人的进展情况

回答by Newtopian

Usually when this happens to me (rare but it does) means that the code being executed is different than the code in the editor. It will happen from time to time for Eclipse that the built classes and the code in editor are out of sync. When that happens I get all sort of weird debugger behavior (debugging empty lines, skipping lines of codes etc).

通常,当我遇到这种情况时(很少见,但确实如此)意味着正在执行的代码与编辑器中的代码不同。Eclipse 时不时会发生构建的类和编辑器中的代码不同步的情况。发生这种情况时,我会遇到各种奇怪的调试器行为(调试空行、跳过代码行等)。

Restarting Eclipse, clean all projects and rebuild everything usually clears things up. I had also the Maven plugins (older versions... had not had it for a while now) that had a tendency to do that too.

重新启动 Eclipse,清理所有项目并重建所有内容通常可以解决问题。我也有 Maven 插件(旧版本......现在已经有一段时间没有了)也有这样做的倾向。

Otherwise it might be a bug, maybe the one Vineet stated,

否则它可能是一个错误,也许是 Vineet 所说的,

Hope this helps

希望这可以帮助

回答by user1164035

Fix could be as simple as clicking run/skip all breakpoints. Worked for me.

修复可以像单击运行/跳过所有断点一样简单。为我工作。

回答by Answerer

Make sure, under Run > Debug Configurations, that 'Stop in main' is selected, if applicable to your situation.

如果适用于您的情况,请确保在运行 > 调试配置下选择了“在主程序中停止”。

回答by Frank Fu

For JDK7, run->Debug Configurations, check "Keep JUnit running after a test run when debugging".

对于JDK7,运行->调试配置,选中“调试时测试运行后保持JUnit运行”。

回答by Mathiouss

Happened to me once, when I had unchecked "Run > Build automatically" and forgot to re-check it.

曾经发生在我身上,当我取消选中“运行 > 自动构建”并忘记重新检查时。

回答by Don Harrington

Make sure you declare the package at the top. In my groovy code this stops at breakpoints:

确保在顶部声明包。在我的常规代码中,这在断点处停止:

package Pkg1

import java.awt.event.ItemEvent;

isMule = false

class LineItem {
    // Structure defining individual DB rows
    public String ACCOUNT_CODE
    public String ACCOUNT_DESC
...

This does not stop at breakpoints:

这不会在断点处停止:

import java.awt.event.ItemEvent;

isMule = false

class LineItem {
    // Structure defining individual DB rows
    public String ACCOUNT_CODE
    public String ACCOUNT_DESC
...

回答by Cyrois

To remove the breakpoints:

要删除断点

  1. Debug your class as a junit test
  2. When your debugger stops, click the "breakpoints" tab next to "variables" and "expressions"
  3. At the top right of the breakpoint tab, click the button with two 'X'
  4. Stop the test, replace your breakpoint and run the debugger again
  1. 将您的课程作为junit 测试进行调试
  2. 当您的调试器停止时,单击“变量”和“表达式”旁边的“断点”选项卡
  3. 在断点选项卡的右上角,单击带有两个“X”的按钮
  4. 停止测试,替换断点并再次运行调试器

回答by Amir Pauker

One additional comment regarding Vineet Reynolds answer.

关于 Vineet Reynolds 回答的另一条评论。

I found out that I had to set -XX:+UseParallelGCin eclipse.ini

我发现我必须设置-XX:+UseParallelGCeclipse.ini

I setup the virtual machine (vm) arguments as follows

我设置虚拟机(vm)参数如下

-vmargs
-Dosgi.requiredJavaVersion=1.7
-Xms512m
-Xmx1024m
-XX:+UseParallelGC
-XX:PermSize=256M
-XX:MaxPermSize=512M

that solved the issue.

解决了这个问题。

回答by kanaparthikiran

If nothing works-

如果没有任何效果-

  1. Remove that Remote/Local Debug Configuration, and Create a new One.
  2. Add the Source in Debug Configurations.
  1. 删除该远程/本地调试配置,并创建一个新配置。
  2. 在调试配置中添加源。