问题
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:
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">
Any help will be appreciated.
回答1:
I have had the same problem, but reading your post helped me resolve mine. I changed org.eclipse.jdt.core.prefs
as follow:
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 Generation options are checked.
回答2:
In the JAR the line number attributes are missing in the compiled bytecode. With the added source code Eclipse knows the line numbers, but not the Java VM that executes the bytecode and does not see the source code.
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.
The only solution is to recreate the JAR or at least the bytecode (.class
files) with line information of the class(es) where you want to set a breakpoint.
来源:https://stackoverflow.com/questions/20344230/how-to-fix-breakpoint-error-when-debugging-in-eclipse