gpt4 book ai didi

java - 是否可以暂停正在运行的 Java 应用程序,修复问题,重新编译它,然后从暂停的地方运行它?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:09 24 4
gpt4 key购买 nike

我正在使用 Selenium 和 Java 编写测试。我想知道是否有任何方法可以在 Debug模式下运行我的代码,然后如果代码中有任何问题,我暂停应用程序,修复它,重新编译它,然后从暂停的地方运行它。我的 IDE 是 Eclipse Mars。

最佳答案

是的,但仅在代码更改较小的有限情况下。您所说的称为热代码替换。以下解释摘自Eclipse Wiki .

Hot code replace (HCR) is a debugging technique whereby the Eclipse Java debugger transmits new class files over the debugging channel to another JVM. In the case of Eclipse development, this also applies to the VM that runs the runtime workbench. The idea is that you can start a debugging session on a given runtime workbench and change a Java file in your development workbench, and the debugger will replace the code in the receiving VM while it is running. No restart is required, hence the reference to "hot".

HCR has been specifically added as a standard technique to Java to facilitate experimental development and to foster iterative trial-and-error coding. HCR only works when the class signature does not change; you cannot remove or add fields to existing classes, for instance. However, HCR can be used to change the body of a method. HCR is reliably implemented only on 1.4.1 VMs and later, or using any version of the IBM J9 VM. J9 is available in IBM products such as Websphere Studio Device Developer™.

If HCR does not work for you even in a simple Java application and you have confirmed that you are running the application on a supported VM (taking note that the JVM that runs Eclipse may not be the same as the JVM that is running your Java application), you may not have automatic building turned on. Make sure that 'Project > Build Automatically' is checked.

关于java - 是否可以暂停正在运行的 Java 应用程序,修复问题,重新编译它,然后从暂停的地方运行它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36364401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com