MyEclipse Debug模式详解

本文介绍了如何使用Eclipse及其扩展MyEclipse进行JSP和Java应用程序的调试过程。包括设置断点、查看变量状态、条件调试等功能,并通过具体实例演示了整个调试流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Eclipse 3.x

MyEclipse plugin 3.8

(A cheap and quite powerful Extension to Eclipse to develop Web Applications and EJB (J2EE) Applications. I think that there is a test version availalable at MyEclipse.)

 

PDF Version des Tutorials

http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf

Introduction

The Eclipse Platform features a Java debugger that provides all standard debugging functionality, including the ability to perform step execution, setting of breakpoints and values, inspecting variables and values, and to suspend and resume threads. With the extension MyEclipse you are able to debug JSP and included files too.

 

The debug perspective

First we will explain the debug perspective. You can activate the perspective under Windows > Open Perspective > Other...

Alternatively, you can click on the debug icon of the perspective tool bar.

Debug view

The Debug view displays the stack trace for the suspended threads for each target you are debugging. Each entry is the variable state of a method right when it called the next method. The view allows you to manage the debugging of a program in the workbench.

Variables view

The view displays information about the variables in the selected class. You can get information about the variable like value, size and more from this view.

Breakpoints view

The view lists all breakpoints you have set in the workbench project. In this view, you can enable or disable breakpoints, remove them, or add a new ones. You can also double-click a breakpoint to display its location in the editor.

This view also lists Java exception breakpoints, which suspend execution at the point where the exception is thrown. You can add or remove exceptions.

 

Expressions view

You can inspect data from each class of a suspended thread, and other places in this view. It opens automatically when an item is added to the view.

Debug a web project

In the next steps I will explain how you can debug a project. I will refer to the project JSP + Servlet you can download on our site. http://www.laliluna.de/assets/tutorials/java-servlets-jsp-tutorial.zip

Open the class BookEdit.java and set a breakpoint in the method doGet(..) at line 72. You can set a breakpoint by double-click on the info bar on the left edge of the editor, or right click Toggle Breakpoint.

Set the second breakpoint in the bookEdit.jsp file on the HTML start tag at line 14.

Note: If you don't have installed MyEclipse, you can't set a breakpoint in jsp and included files.

To see all breakpoints you can use the Breakpoints view in the debug perspective.

Breakpoint Properties

You can apply some properties to each breakpoint, for example how many times a breakpoint can hit before it suspends the thread or on which condition it suspends the thread.

Select the breakpoint right mouse button and choose the option Breakpoint Properties.

 

Hit Count

The hit count sets a number of times the breakpoint can be executed before the thread suspends. Very helpful in a loop expression or if you want to know the value of a expression after some hits.

Enable Condition

There are two options to suspend a thread by using a condition.

  • if the enabled condition is true

  • if the enabled condition changes

If you want that the condition suspends the thread when it is true select the option condition is true on Suspend when.

Example:

action.equals("edit");

 

If you want that the condition suspends the thread when the value of the condition changes select the option value of the condition changes on Suspend when.

 

 

Suspend Policy

You can define if the breakpoint suspends only the thread or the complete virtual machine.

Deploy and Debug

Now we want to debug the project, so deploy it and call it in your web browser. Choose Edit on the list of books.

After you clicked the Edit link, eclipse shows you the following confirm window. You can choose if you want to switch to the debug perspective. Yes, you want it ;- )

The first entry in the debug view represents the state of the method where the breakpoint was set. You can preview the state of a entry simply by clicking on it, also the file will be open where the method is placed.

You can see the values of all variables of the selected entry in the Variables view.

A marked line and an arrow at the breakpoint shows that the debugger is suspended on this line.

If you've decided that you missed an important place in the execution process, perhaps the breakpoint was in the wrong place, or maybe you accidentally stepped over some code you wanted to inspect earlier in the process. Eclipse has a feature called Drop to frame, that essentially lets you 'rewind' the execution to the beginning of any method in the stack. This is especially useful when you perform variable modification or code hot swapping. Right click on the frame and choose the option Drop to Frame.

 

 

Inspect expressions

To get informations about expression, you can inspect a expression. Right click on the marked expression, you want to inspect and choose Inspect or press Ctrl + Shift + I. A pop-up window appears that holds the informations about the expression.

 

Watch expressions

Watch is similar to inspect an expression. Watch means that the expression will be added to the Expressions view, where you can watch the informations about the expression. Add two expressions to the Expressions view.

Mark the expressions, right click and choose Watch.

Now the two expression are in the Expressions view.

 

Display expressions

If you want to display the type and the value of an expression, mark the expression and choose the Display option from the context menu (right mouse button) or press Ctrl + Shift + D.


Run to Line

If you set a breakpoint and somewhere under the breakpoint is a line you want to go, you can use the option Run to Line. The code between the breakpoint and the selected line will be executed. Select the line you want to go, press the right mouse button and choose the option Run to Line or use the key binding Ctrl + R.


Debugging JSP files (supported by MyEclipse)


Debugging a JSP file is the same like debugging a Java class, but the most features (Watch, Inspect, etc) are not implemented. The only way to get the values of variables is the Variables view.

 

That's it. You will only need to debug, when you make mistakes. Avoid them and forget the tutorial

<think>我们正在处理用户关于Eclipse调试时断点无效的问题。根据引用内容,我们可以总结出几种可能的解决方法。 首先,我们需要确认断点是否被禁用或跳过。引用[3]提到,如果断点被右键禁用了,或者主菜单中的“Skip all breakpoints”被勾选,那么断点会被跳过。 其次,引用[2]提到,在某个工程中断点无效,而在其他工程有效,说明问题可能出在该工程的特定设置上。他们尝试了多种方法,其中第5步(勾选“Add line number attributes to generated class files”)可能是关键。 另外,引用[1]也提到了同样的设置(添加行号属性到生成的类文件)是解决断点无效的一个方法。 因此,我们可以按照以下步骤来尝试解决: 步骤1:检查是否全局跳过了所有断点 在Eclipse菜单栏中,点击Run -> 查看Skip All Breakpoints是否被勾选。如果被勾选,请取消勾选。 步骤2:检查断点是否被禁用 在Breakpoints视图中(Window -> Show View -> Breakpoints),查看每个断点是否被禁用(断点图标上有一个斜线圆圈)。如果被禁用,右键点击断点,选择“Enable”。 步骤3:检查编译器设置 1. 打开菜单Window -> Preferences -> Java -> Compiler。 2. 确保“Classfile Generation”下的“Add line number attributes to generated class files (used by the debugger)”被勾选。如果没有,请勾选上。 3. 点击Apply and Close。 步骤4:重新编译项目 在修改了编译器设置后,需要重新编译项目(Project -> Clean... -> 选择你的项目)。 步骤5:检查调试设置 1. 打开菜单Window -> Preferences -> Java -> Debug。 2. 确保“Suspend execution on uncaught exceptions”和“Suspend execution on compilation errors”没有被勾选(虽然引用[2]提到去掉这两个勾选,但通常它们不影响断点生效,不过可以尝试)。 3. 将“Debugger timeout (ms)”设置为15000或更高。 步骤6:删除并重新设置断点 有时候断点本身可能有问题,可以尝试删除所有断点(在Breakpoints视图中,右键->Remove All),然后重新设置断点。 步骤7:检查项目构建路径和依赖 如果项目是Maven工程,确保依赖正确,并且没有编译错误。如果有编译错误,断点可能会被跳过。 步骤8:重启Eclipse 有时候重启Eclipse可以解决一些临时性问题。 如果以上步骤都不能解决问题,可能需要考虑Eclipse本身的bug或者工作空间损坏。可以尝试新建一个工作空间,重新导入项目。 注意:以上步骤中,步骤3(添加行号属性)是最关键的,因为调试器需要行号信息来定位断点。 引用说明: [^1] 提到了添加行号属性到生成的类文件。 [^2] 详细描述了在特定工程中断点无效的问题,并尝试了多种方法,其中勾选行号属性是其中之一。 [^3] 提到了跳过所有断点的设置。 相关问题: 1. 为什么在Eclipse中调试时,断点会变成灰色? 2. 如何解决Eclipse调试时无法进入源码的问题? 3. Eclipse调试时遇到“Source not found”错误怎么办?</think>### Eclipse 调试时断点无效的解决方法 以下是针对 Eclipse 调试时断点无效问题的系统化解决方案,按优先级排序: #### 1. **检查断点全局设置**(最高频原因) - 进入菜单栏:**Run → Skip All Breakpoints** - 若该选项被勾选,**取消勾选**(此操作会跳过所有断点)[^3] - 验证方法:查看断点图标,正常为蓝色实心圆●,被跳过时变为带斜线的空心圆⦻ #### 2. **启用行号属性**(关键编译设置) 1. 打开设置:**Window → Preferences → Java → Compiler** 2. 勾选:**Add line number attributes to generated class files**(确保调试器可定位代码行) 3. 应用后**重新编译项目**(Project → Clean)[^1][^2] #### 3. **验证工程特定配置**(针对单个工程失效) - 检查`.classpath`文件是否包含调试属性: ```xml <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> <attributes> <attribute name="owner.project.facets" value="java"/> </attributes> </classpathentry> ``` - 若缺失,右键工程 → **Build Path → Configure Build Path** → 检查JRE系统库[^2] #### 4. **调试器超时设置** 1. **Window → Preferences → Java → Debug** 2. 调整 **Debugger timeout (ms)** 至 ≥15000ms 3. 取消勾选: - ☐ Suspend execution on uncaught exceptions - ☐ Suspend execution on compilation errors[^2] #### 5. **断点状态重置** 1. 打开断点视图:**Window → Show View → Breakpoints** 2. 移除所有断点:右键 → **Remove All** 3. 重新添加断点(避免断点对象损坏) #### 6. **环境清理操作** ```mermaid graph LR A[删除工程] --> B[关闭Eclipse] B --> C[删除工作空间/.metadata/.plugins目录] C --> D[重新导入工程] ``` 此操作可解决元数据损坏问题,尤其适用于Maven工程[^2] #### 7. **JDK调试兼容性** - 确认项目使用的JDK与Eclipse默认JRE一致 - 检查位置:**Window → Preferences → Java → Installed JREs** > **注意**:若使用热部署插件(如JRebel),需在插件设置中启用**Enable debugging support**。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值