官术网_书友最值得收藏!

Time for action – updating code in the debugger

When an Eclipse instance is launched in run mode, changes made to the source code aren't reflected in the running instance. However, debug mode allows changes made to the source to be reflected in the running target Eclipse instance.

  1. Launch the target Eclipse in debug mode by clicking on the debug icon.
  2. Click on the hello world icon in the target Eclipse to display the dialog, as before, and click on OK to dismiss it. It may be necessary to remove or resume the breakpoint in the host Eclipse instance to allow execution to continue.
  3. In the host Eclipse, open the SampleHandler class and go to the execute method.
  4. Change the title of the dialog to Hello again, Eclipse world and save the file. Provided the Build Automatically option in Project menu is enabled, the change will be automatically recompiled.
  5. Click on the hello world icon in the target Eclipse instance again. The new message should be shown.

What just happened?

By default, Eclipse ships with the Build Automatically option in Project menu enabled. Whenever changes are made to Java files, they are recompiled along with their dependencies if necessary.

When a Java program is launched in run mode, it will load classes on demand and then keep using that definition until the JVM shuts down. Even if the classes are changed, the JVM won't notice that they have been updated, and so no differences will be seen in the running application.

However, when a Java program is launched in debug mode, whenever changes to classes are made, Eclipse will update the running JVM with the new code if possible. The limits to what can be replaced are controlled by the JVM through the Java Virtual Machine Tools Interface (JVMTI). Generally, updating an existing method and adding a new method or field will work, but changes to interfaces and superclasses may not be.

Note

The Hotspot JVM cannot replace classes if methods are added or interfaces are updated. Some JVMs have additional capabilities that can substitute more code on demand. Other JVMs, such as IBM's, can deal with a wider range of replacements.

Note that there are some types of changes that won't be picked up, for example, new extensions added to the plugin.xml file. In order to see these changes, it is possible to start and stop the plug-in through the command-line OSGi console, or restart Eclipse inside or outside of the host Eclipse to see the change.

Debugging with step filters

When debugging using Step Into, the code will frequently go into Java internals, such as the implementation of Java collections classes or other internal JVM classes. These don't usually add value, so fortunately Eclipse has a way of ignoring uninteresting classes.

主站蜘蛛池模板: 信宜市| 南丹县| 绵竹市| 文昌市| 古丈县| 浑源县| 思茅市| 蕉岭县| 基隆市| 永修县| 赤水市| 紫金县| 读书| 额济纳旗| 绵阳市| 兴隆县| 万年县| 宜宾市| 新丰县| 富宁县| 黑河市| 龙江县| 蒙山县| 澎湖县| 雅安市| 阳信县| 轮台县| 威远县| 宜兴市| 呼和浩特市| 陈巴尔虎旗| 巩留县| 年辖:市辖区| 嘉鱼县| 高密市| 榆中县| 泾川县| 江山市| 延长县| 喀喇沁旗| 陆川县|