Java 在 Eclipse 中调试时如何修复断点错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20344230/
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
How to fix breakpoint error when debugging in Eclipse?
提问by Scoket Joe
Need to debug a JAR file "ProA", so import the source code in the project, but there is a strange error in Eclipse while trying to set a breakpoint. Detail as below:
需要调试一个JAR文件“ProA”,所以在项目中导入源代码,但是在Eclipse中尝试设置断点时出现一个奇怪的错误。详情如下:
Unable to install breakpoint due to missing line number attributes.
Modify compiler options to generate line number attributes.
I have try to several method to solve, but failed.
我尝试了几种方法来解决,但都失败了。
- Under Window > Preferences: Java > Compiler > Classfile Generation, all options have to be to True
- In
.settings
folder of your project, look for a file calledorg.eclipse.jdt.core.prefs
. Verify or setorg.eclipse.jdt.core.compiler.debug.lineNumber=generate
- Add the
debug=true
flag in thebuild.xml
, just like this:<javac srcdir="./src/java" destdir="./bin" debug="true">
- 在Window > Preferences: Java > Compiler > Classfile Generation 下,所有选项都必须为 True
- 在
.settings
您的项目文件夹中,查找名为org.eclipse.jdt.core.prefs
. 验证或设置org.eclipse.jdt.core.compiler.debug.lineNumber=generate
- 在 中添加
debug=true
标志build.xml
,就像这样:<javac srcdir="./src/java" destdir="./bin" debug="true">
Any help will be appreciated.
任何帮助将不胜感激。
回答by Agostinho
I have had the same problem, but reading your post helped me resolve mine. I changed org.eclipse.jdt.core.prefs
as follow:
我遇到了同样的问题,但是阅读您的帖子帮助我解决了我的问题。我改变org.eclipse.jdt.core.prefs
如下:
BEFORE:
前:
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
AFTER:
后:
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Another way to modify these options within the Project> Properties> Java Compiler. So, there is no need to modify manually the org.eclipse.jdt.core.prefs
file. There you need to make sure that the Classfile Generationoptions are checked.
在 Project> Properties> Java Compiler 中修改这些选项的另一种方法。因此,无需手动修改org.eclipse.jdt.core.prefs
文件。在那里您需要确保选中Classfile Generation选项。
回答by howlger
In the JAR the line number attributes are missing in the compiled bytecode. With the added source code Eclipse knowsthe line numbers, but not the Java VMthat executes the bytecode and does not see the source code.
在 JAR 中,编译的字节码中缺少行号属性。添加源代码后,Eclipse 知道行号,但不知道执行字节码且看不到源代码的 Java VM。
It would be useless if Eclipse told the Java VM to stop at a specific line, because the Java VM does not know which command is in which line and so when to stop.
如果 Eclipse 告诉 Java VM 在特定行停止,那将是无用的,因为 Java VM 不知道哪个命令在哪一行以及何时停止。
The only solution is to recreate the JARor at least the bytecode (.class
files) with line informationof the class(es) where you want to set a breakpoint.
唯一的解决方案是重新创建 JAR或至少包含要设置断点的类的行信息的字节码(.class
文件)。
回答by senerg
****Window -> Preferences -> Compiler **** For debugging we need producing line number in class files. after selecting "Add Line Number attributes to generated class files (used by debugger), rebuild the project and run your debugger to see line numbers and breakpoint, and execution pointer. enter image description here
****Window -> Preferences -> Compiler **** 为了调试,我们需要在类文件中生成行号。选择“将行号属性添加到生成的类文件(由调试器使用)后,重建项目并运行调试器以查看行号和断点以及执行指针。 在此处输入图像描述