publickey's article "[Free code editor VS Code realizes" Hot Code Replacement "that can dynamically rewrite and modify the code of a running Java application" (http://www.publickey1.jp Inspired by "/blog/18/vscodejavahot_code_replacement.html)", I tried using VSCode.
Download / install Stable Build from https://code.visualstudio.com. Currently version 1.19.
--Open Extension (Ctrl + Shift + X) view --Install Java Extension Pack (Debugger for Java, Laguage Support for Java is also installed) --Open the setting screen (Ctrl +,) and set * java.home * according to your environment.
Hello, World! First, let's write Hello, World !. --File-Open Folder --Select a new file --Select Java in the language mode selection at the bottom right. Character code and line feed code are your choice --It seems that * templates * such as main and sysout are prepared. --Save As (Ctrl + Shift + S). * Classpath is incomplete. Only syntax errors will be reported * Ignore the warning for now. --You can run the program by starting debugging (F5), but the * launch.json * file will be created the first time, so run it again with F5. --The debug view opens as shown below, and the execution result is displayed on the console.
Naturally, I would like to say that Japanese is displayed without any problem, but it was not so sweet. If you keep the default, the console display will be garbled as shown below.
To handle this, open the settings screen and add **-Dfile.encoding = utf8 ** to * java.jdt.ls.vmargs *. Since it is a JVM argument, I thought it would be okay to change the order and character code to * UTF-8 *, but even if I add **-Dfile.encoding = UTF-8 ** to the end of the original value It was no good. * "java.jdt.ls.vmargs": "-noverify -Dfile.encoding = utf8 -Xmx1G -XX: + UseG1GC -XX: + UseStringDeduplication" * The garbled characters could be resolved by adding.
Modify the program as follows to try * Hot Code Replacement *.
Test.java
public class Test {
public static void main(String[] args) {
for (int i = 0; i < 10; i++)
sayHello();
}
private static void sayHello() {
System.out.println("Hello World!");
}
}
Set a breakpoint at the place where you call the * sayHello () * method and start debugging. --Stop at breakpoint -* sayHello () * Rewriting the method. Save --Continue (F5) By repeating, you can see that the processing of the * sayHello () * method has been replaced without restarting the program.
Using VSCode, I was able to check the * Hot Code Replacement * of the Java program. Finally, the settings I added to develop Java with * VS Code * are as follows.
{
"java.home": "Set the JDK path",
"java.jdt.ls.vmargs": "-noverify -Dfile.encoding=utf8 -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication",
"java.debug.settings.enableHotCodeReplace": true,
}
I'd like the console to handle garbled characters by default, but I'm glad that I could handle it by adding a little setting.
Functionally, it's not enough compared to the * Eclipse * that I usually use, but above all, the lightness of this operation is attractive. It is said that it also supports * Spring Boot *, so if you have a chance, try it.
Recommended Posts