Java 无法在日食中放置断点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2415655/
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-13 07:18:50  来源:igfitidea点击:

unable to place breakpoints in eclipse

javaeclipsedebuggingbreakpointsjdk1.6

提问by anjanb

I am using eclipse europa (3.5) on windows vista home premium 64-bit using JDK 1.6.0_18 (32 BIT).

我使用 JDK 1.6.0_18(32 位)在 windows vista 家庭高级版 64 位上使用 eclipse europa(3.5)。

Normally, I am able to put breakpoints just fine; However, for a particular class which is NOT part of the project (this class is inside a .JAR file (.JAR file is part of the project) ), although I have attached a source directory to this .JAR file, I am unable to place a breakpoint in this class.

通常,我可以很好地放置断点;但是,对于不属于项目的特定类(此类位于 .JAR 文件中(.JAR 文件是项目的一部分)),尽管我已将源目录附加到此 .JAR 文件中,但我无法在这个类中放置一个断点。

If I double-click on the breakpoint pane(left border), I notice that a class breakpoint is placed. I was wondering if there was NO debug info; However, found that this particular class was compiled using ant/javac task using debug="true" and debuglevel="lines,vars,source". I even ran jad on this class to confirm that it indeed contained the debug info.

如果我双击断点窗格(左边框),我会注意到放置了一个类断点。我想知道是否没有调试信息;然而,发现这个特定的类是使用 ant/javac 任务使用 debug="true" 和 debuglevel="lines,vars,source" 编译的。我什至在这个类上运行 jad 以确认它确实包含调试信息。

So, why is eclipse preventing me from placing a breakpoint ?

那么,为什么 eclipse 阻止我放置断点?

EDIT : Just so everyone understands the context, this is a webapp running under tomcat 6.0. I am remote debugging the application from eclipse after having started tomcat outside. The application is working just fine. I am trying to understand the behavior of the above class which I'm unable to do since eclipse is not letting me set a BP.

编辑:为了让每个人都了解上下文,这是一个在 tomcat 6.0 下运行的 webapp。在外面启动 tomcat 后,我​​正在从 eclipse 远程调试应用程序。该应用程序运行良好。我试图了解上述类的行为,因为 eclipse 不允许我设置 BP,因此我无法做到这一点。

P.S : I saw a few threads here talking about BPs not being hit but in my case, I am unable to place the BP!

PS:我在这里看到一些讨论 BP 没有被击中的话题,但就我而言,我无法放置 BP!

P.P.S : I tried JDK 1.6.0_16 before trying out 1.6.0_18.

PPS:在尝试 1.6.0_18 之前,我尝试了 JDK 1.6.0_16。

Thanks for any pointers.

感谢您的指点。

回答by richj

It sounds like Eclipse cannot find the jar file on the classpath, although you did say that the jar file is part of the project. What happens if you run the application normally? Do you get a ClassDefNotFoundException or something similar?

听起来 Eclipse 在类路径上找不到 jar 文件,尽管您确实说过 jar 文件是项目的一部分。如果您正常运行应用程序会发生什么?你得到一个 ClassDefNotFoundException 或类似的东西吗?

If you check the tabs on the Run/Debug configuration you should be able to see what paths and jar files are on the classpath at runtime. You can also add jar files that are not needed to build the application but are needed to run it.

如果您检查运行/调试配置上的选项卡,您应该能够看到运行时类路径上的路径和 jar 文件。您还可以添加构建应用程序不需要但运行应用程序所需的 jar 文件。

回答by Claudio

Try to take a look at your configuration Java->debug->Step filtering sometime its enabled and you cannot stop inside a filtered package

尝试查看您的配置 Java->debug->Step 过滤有时它已启用,并且您无法在已过滤的包内停止

回答by Chris Lercher

although I have attached a source directory to this .JAR file, I am unable to place a breakpoint in this class.

尽管我已将源目录附加到此 .JAR 文件,但我无法在此类中放置断点。

You say "a source directory". Are you sure, it's the same version that was used to compile the jar? If you're attaching a different source code version, the line numbers may not match, and your break point won't hit.

你说“一个源目录”。您确定,它与用于编译 jar 的版本相同吗?如果您附加不同的源代码版本,行号可能不匹配,并且您的断点不会命中。

回答by Cshah

I m aware of a bug in eclipse where break points dont work with a specific version of jdk 1.6.x For more info look at here

我知道 eclipse 中的一个错误,其中断点不适用于特定版本的 jdk 1.6.x 有关更多信息,请查看此处

回答by Vaishak Suresh

Use a plugin called Jadclipse to decompile the jar in runtime, place the breakpoint at the point where the JAR method is invoked, then press F6 and you should be able to go into your JAR method.

使用名为 Jadclipse 的插件在运行时反编译 jar,将断点放置在调用 JAR 方法的位置,然后按 F6,您应该可以进入您的 JAR 方法。

回答by Vaishak Suresh

Step1: Toggle/Enable breakpointSet the breakpoint at the line of code or point of method entry from where you would like to start debugging the code. Right click on the left margin of the editor next to the line of code and a context menu pops up. Select toggle breakpoint in the context menu

第 1 步:切换/启用断点在您希望开始调试代码的代码行或方法入口点设置断点。右键单击代码行旁边编辑器的左边距,弹出上下文菜单。在上下文菜单中选择切换断点

Step2: Configure the breakpoint to stop executionTo start debugging, the execution should stop at the breakpoint specified. For this click on breakpoint properties and do the following:

Step2:配置断点停止执行要开始调试,应在指定的断点处停止执行。为此,单击断点属性并执行以下操作:

1. Check Hit count
2. Specify value as 1
3. Select “Suspend thread” option

This will stop the execution when the program hits the breakpoint.

这将在程序遇到断点时停止执行。

Step3: Switch to debug perspective

Step3:切换到调试视角

In Eclipse, select Window –>Open Perspective –> Debug

在Eclipse中,选择Window –>Open Perspective –> Debug

Step4: Run in debug mode

Step4:在调试模式下运行

Now run the program in debug mode. Select Run –> Debug

现在在调试模式下运行程序。选择运行->调试

Now the program starts running in debug mode and you would see the state of the thread as “running”

现在程序开始在调试模式下运行,您会看到线程的状态为“正在运行”

When the program hits the breakpoint the state of the thread changes from “running” to “suspended”

当程序遇到断点时,线程的状态从“运行”变为“挂起”

Step5: Debugging the code with Expressions \Watch variables \ Inspect

Step5:使用 Expressions \Watch variables \ Inspect 调试代码

Now the code stops at the breakpoint. You could use the watch variables / expression to monitor the current value of the debug variable. Suppose you set the breakpoint at the variable named “counter” and the program stopped at counter variable Add the expression with the variable name “counter” which allows you to monitor the value of the variable as you execute the program You could also right click on the counter variable and select “Inspect” from the context menu If it is a method then, select the method name and click on “Step Into Selection“. This will allow you to monitor or debug the method execution line by line.

现在代码在断点处停止。您可以使用监视变量/表达式来监视调试变量的当前值。假设您在名为“counter”的变量处设置断点,并且程序在 counter 变量处停止 添加变量名为“counter”的表达式,它允许您在执行程序时监视变量的值 您也可以右键单击计数器变量并从上下文菜单中选择“检查”如果它是一个方法,则选择方法名称并单击“步入选择”。这将允许您逐行监视或调试方法执行。

Step6: Use F6 key to step into the method

Step6:使用F6键进入方法

To “step into” the next executable line of code in the current method, press the “F6 Key”. This will pass the program control from the current line to the next executable line of code.

要“步入”当前方法中的下一个可执行代码行,请按“F6 键”。这会将程序控制权从当前行传递到下一个可执行代码行。

回答by user2246494

When trying at add breakpoints for a .jsp page it turned out the page was not opened with a JSP editor, which prevented the setting of breakpoints.

当尝试为 .jsp 页面添加断点时,结果发现该页面不是用 JSP 编辑器打开的,这阻止了断点的设置。

回答by user104309

Just a simple refresh of the .jar file did the trick for me.

对 .jar 文件的简单刷新对我来说就成功了。

I was able to place breakpoints in all the other class files of the same package except one. What I observed is that, when I opened this class file in editor and selected "Link with Editor", eclipse did not take me to this class file itself, but only to the package of this class file.

我能够在同一个包的所有其他类文件中放置断点,除了一个。我观察到的是,当我在编辑器中打开这个类文件并选择“与编辑器链接”时,eclipse并没有带我到这个类文件本身,而是只带我到这个类文件的包。

After the refresh,"Link with Editor" worked and I was able to place the breakpoint.

刷新后,“与编辑器链接”工作,我能够放置断点。

If someone could explain this behavior,it will be helpful.

如果有人可以解释这种行为,那将很有帮助。