如何启用 Intellij 热代码交换

发布于 2024-11-16 06:59:20 字数 797 浏览 3 评论 0原文

Intellij 似乎没有在我的安装上进行基本的热代码交换。

对于这段代码:

public class MainTest {
    public void method1() {
        System.out.println("Breakpoint here");
    }

    public void method2() {
        System.out.println("Line that will get 24 modified");
    }

    public static void main(String[] args) {
        System.out.println("First print here");
        MainTest mainTest = new MainTest();
        mainTest.method1();
        mainTest.method2();
        System.out.println("Line that I do not modify");
    }
}

我在 mainTest.method1(); 上放置了一个断点,然后修改 method2() 处的字符串,点击 ctrl+s 并继续一步一步进行。不幸的是,运行时未更新,正在打印旧字符串。句号 - 编译 - 运行确实打印新字符串。所以我的结论是热插拔不​​起作用。

我需要设置任何设置才能启用热代码交换吗?

  • Ubuntu、JDK 1.6
  • Intellij 10.5 Ultimate(评估)

Intellij does not seem to be doing basic hot code swap on my installation.

For this code:

public class MainTest {
    public void method1() {
        System.out.println("Breakpoint here");
    }

    public void method2() {
        System.out.println("Line that will get 24 modified");
    }

    public static void main(String[] args) {
        System.out.println("First print here");
        MainTest mainTest = new MainTest();
        mainTest.method1();
        mainTest.method2();
        System.out.println("Line that I do not modify");
    }
}

I put a breakpoint on mainTest.method1(); then modify the string at method2(), hit ctrl+s and continue to step by step. Unfortunately the runtime is not updated, old string is being printed. Full stop - compile - run does print the new string. So my conclusion is hot-swap not working.

Is there any settings I need to set to enable hot code swap?

  • Ubuntu, JDK 1.6
  • Intellij 10.5 Ultimate (evaluation)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

风蛊 2024-11-23 06:59:20

在等待断点时保存类后,只需使用 Build -> 重新编译类即可。编译“MainTest.java” 或使用标准键绑定按 Ctrl+Shift+F9

然后,IntelliJ IDEA 将显示一个小对话框,询问您是否要重新加载该类。

After saving your class while waiting on your breakpoint just recompile your class with Build -> Compile 'MainTest.java' or press Ctrl+Shift+F9 with the standard key bindings.

IntelliJ IDEA will then show a small dialog in which it asks you if you want to reload that class.

浮生面具三千个 2024-11-23 06:59:20

经过以下修改并启用热插拔后,Java 文件中的更改需要 1-2 秒的重新启动时间。 (对于我来说,初始启动时间约为 7 秒)。

我希望下面的方法可以帮助...


首先,您需要在首选项菜单中选中“自动创建项目”。

打开首选项菜单;

您可以转到顶部菜单并单击;

IntelliJ IDEA ->偏好设置

或您可以通过键盘输入以下快捷方式;

cmd + 选项 + s

然后,您可以勾选自动生成项目,如下图所示;

输入图像描述这里

其次,您需要将compiler.automake.allow.when.app.running注册表设置修改为true。

要打开注册表,您需要单击下面的键盘快捷键:

cmd + Shift + a

输入registry,如下图所示,选择Registry,然后按键盘回车键;

输入图像描述这里

打开Registry窗口后,输入compiler.automake以查看compiler.automake.allow.when.app.running选项,并将其检查为在下图中;

输入图像描述这里

然后,您需要重新启动 IntelliJ 以使注册表更改生效。

After below modifications and enabling hot swap, a change in a Java file took 1-2 seconds of restart time. (Initial start time is around 7 seconds for me).

I hope below method helps...


First, you need to check “Make project automatically” in preferences menu.

To open preferences menu;

you can go to top menu and click;

IntelliJ IDEA -> Preferences

or you can type below shortcut via keyboard;

cmd + option + s

Then, you can check Make project automatically as in below picture;

enter image description here

Secondly, you need to modify compiler.automake.allow.when.app.running registry setting as true.

To open registry, you need to click below keyboard shortcut:

cmd + shift + a

Type registry as in below picture, select Registry, and hit enter button of keyboard;

enter image description here

After Registry window opened, type compiler.automake to see compiler.automake.allow.when.app.running option, and check it as in below picture;

enter image description here

Then, you need to restart IntelliJ to make registry changes work.

倾城泪 2024-11-23 06:59:20

进入设置-->选择调试-->热交换

输入图片此处描述

Go to Setting --> Select Debug --> HotSwap

enter image description here

灯下孤影 2024-11-23 06:59:20

有一个调试器> intellij 11 中的 HotSwap 选项。

There is a Debugger > HotSwap option in intellij 11.

你的心境我的脸 2024-11-23 06:59:20

我希望每次保存 Java 文件时热交换都能自动运行。其他答案都没有这样做,所以我只是:

  1. 创建了一个将在保存时运行的宏: https://stackoverflow.com/a/ 5581992/14731
  2. 在宏末尾添加了 Action: HotswapRun -> Reload Changed Classes

I wanted hotswap to automatically run every time I saved a Java file. None of the other answers did this so I just:

  1. Created a macro that will run on save: https://stackoverflow.com/a/5581992/14731
  2. Added Action: Hotswap at the end of the macro (Run -> Reload Changed Classes)
凑诗 2024-11-23 06:59:20

我想你是在问这个,

  1. 右键单击你的java类
  2. 选择编译并重新加载文件

I think you are asking about this,

  1. Right-click on your java class
  2. Select Compile And Reload File
巾帼英雄 2024-11-23 06:59:20

对于遇到与我相同问题的人,您可能遇到了以下影响 2020.2 更新的最新错误https://youtrack.jetbrains.com/issue/IDEA-247530?_ga=2.116305920.729836936.1599654650-984156210.1599654650

TL;DR 作为解决方法,您需要重新激活Groovy 插件。

For anyone experiencing the same problem as me, you might have incurred in the following recent bug affecting the 2020.2 update: https://youtrack.jetbrains.com/issue/IDEA-247530?_ga=2.116305920.729836936.1599654650-984156210.1599654650

TL;DR As a workaround, you need to re-activate the Groovy plugin.

云仙小弟 2024-11-23 06:59:20

我在Ubuntu上遇到了这个问题。我还遇到了一个明显不相关的问题,IntelliJ 给出了有关文件监视限制的错误(抱歉,我不再有确切的错误消息)。为了解决后面的问题,我执行了以下步骤:

  1. 将以下行添加到 /etc/sysctl.conf 文件或新的 *.conf 文件(例如 idea.conf< /code>)在/etc/sysctl.d/目录下:

    <前><代码>fs.inotify.max_user_watches = 524288

  2. 然后运行此命令来应用更改:

    sudo sysctl -p --system

现在我的 React 组件重建和热插拔就好了。

来源

I encountered this problem on Ubuntu. I also had an apparently unrelated issue where IntelliJ gave an error about the file watch limit (my apologies that I no longer have the exact error message). To solve this later issue I did the following steps:

  1. Add the following line to either /etc/sysctl.conf file or a new *.conf file (e.g. idea.conf) under /etc/sysctl.d/ directory:

    fs.inotify.max_user_watches = 524288
    
  2. Then run this command to apply the change:

    sudo sysctl -p --system

Now my React components rebuild and hot swap just fine.

Source

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文