How to enable Intellij hot code swap

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

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)

回答1:

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.



回答2:

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 ,

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

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 "Registery", and hit enter button of keyboard;

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

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



回答3:

There is a Debugger > HotSwap option in intellij 11.



回答4:

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



回答5:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!