Skip to content

Hot Deploy beta

INFO

Hot deployment is complex and requires a lot of compatibility. If this project helps you save development time, you might as well click . Your recognition will make more people discover it, and your support is my motivation to update. If it doesn't work, please submit to give feedback.

1. What is hot deployment

The traditional deployment process is generally submit code->pull code->package->deploy->restart project before the written code can take effect.

Hot deployment can skip this tedious process. After the developer modifies the code, there is no need to manually trigger packaging or restart the service. The application can load the new logic and run in seconds, greatly shortening the feedback cycle.

Hot deployment is based on hot reload. Hot reload only supports local environment, while hot deployment allows remote applications to be hot reloaded.

2. Enable hot deployment

TIP

Hot deployment requires a specific JDK to take effect. Please refer to JDK Installation to complete JDK initialization.

2.1 Add JVM parameters

[Java 8] Add the following JVM parameters when starting.

shell
-XXaltjvm=dcevm -javaagent:${agentPath}/debug-tools-agent.jar=${conf}

[Java 11] Add the following JVM parameters when starting.

shell
-javaagent:${agentPath}/debug-tools-agent.jar=${conf} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/com.sun.beans=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.introspect=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.util=ALL-UNNAMED --add-opens java.base/sun.security.action=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED

[Java 17/21] Add the following JVM parameters when starting.

shell
-XX:+AllowEnhancedClassRedefinition -javaagent:${agentPath}/debug-tools-agent.jar=${conf} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED --add-opens java.desktop/com.sun.beans=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.introspect=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.util=ALL-UNNAMED --add-opens java.base/sun.security.action=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED
  • agentPath is the path of debug-tools-agent.jar
  • conf is the configuration information passed to the agent, in the format of key1=value1,key2=value2

2.2 Optional configuration

Optional keyMeaningValueExample
hotswapWhether to enable hot reload/hot deploymenttrue: Enable
false: Disable
true
serverWhether to start the server for client connectionstrue: Enable
false: Disable
true
tcpPortTCP port to listen to (valid only when server=true)Available ports12345
httpPortHTTP port to listen to (valid only when server=true)Available ports22222
printSqlWhether to print the executed SQL statementtrue: Enable
false: Disable
true
propertiesFilePathExternal configuration file pathConfiguration file address/etc/debug-tools/conf/debug-tools-agent.properties

propertiesFilePath configuration

keymeaningdefault value
hotswapwhether to enable hot reload/hot deployment (same as above)true
serverwhether to start the server for client connection (same as above)true
tcpPortTCP port to listen on (valid only when server=true) (same as above)default, start from 12345 to find available ports
httpPortHTTP port to listen on (valid only when server=true) (same as above)default, start from 22222 to find available ports
lombokJarPathlombok.jar path, if lombok is used during remote dynamic compilation, it needs to be specified to compile (same as above)-
printSqlwhether to print the executed SQL statementfalse
includedClassLoaderPatternsClassLoader to initialize hot reload/hot deployment. Only one of the excludedClassLoaderPatterns can be configured at the same time-
excludedClassLoaderPatternsThe ClassLoader to be excluded from initialization reloading/hot deployment. Only one can be configured at the same time with includedClassLoaderPatterns-
pluginPackagesScan plugins written on other paths, multiple paths are separated by commas-
extraClasspathMacOS/Linux loads extended class file path/var/tmp/debug-tools/classes
extraClasspathWinWindows loads extended class file pathc:/var/tmp/debug-tools/classes
watchResourcesMacOS/Linux monitor resource path/var/tmp/debug-tools/resources
watchResourcesWinWindows monitor resource pathc:/var/tmp/debug-tools/resources
spring.basePackagePrefixSpring base package prefix, multiple paths are separated by commas-
disabledPluginsDisabled plugins, multiple commas are separated-
autoHotswapWhether to automatically hot reload. Reloads class definitions in a running application after watching for changed class files in the ClassLoader's resources path. It uses the Java Instrumentation API to reload class bytecode.false
autoHotswap.portJPDA connection port, listens for changed files and performs hot reload, you need to specify the JPDA port when starting.-

3. Connecting to a remote service

Click the toolbar on the right side of Idea to wake up the DebugTools window, and click Connect to fill in the remote address.

connect_tools_window

Enter host, tcpPort and httpPort, and click the Save & Connent button to connect the remote application.

connect_input.png

After successfully attaching the application, DebugTools will display the attachment status.

  • R: indicates that the application is a remote application, and L indicates that it is a local application.
  • Connected: the application has been successfully attached and connected to the service.
  • i.g.f.d.t.t.a.DebugToolsTestApplication: the application name.
    • Specified application name if the application name is specified during attachment.
    • If the application name is not specified, the spring.application.name configuration item is used if it is a Spring application.
    • If not specified, the Main-Class in the jar at startup is used.
    • If not found, the sun.java.command in the startup command is used.

remote_attach_status

4. Using hot reload

4.1 Multiple files

Click the button to wake up the main page.

hot_deploy_button.png

After selecting the file to be deployed

hot_deploy_dialog.png

  • Compiler Type: file compilation method
    • Local Intellij Idea: compile the changed files through the idea compiler
    • Remote Attach Application: remote dynamic compilation of the changed files through the attached application
  • Select Type: file selection method
    • Java: changed java files
    • Resources: changed resource files (pending)
    • Vcs: select to obtain file changes through the vcs tool, and do not select to obtain file changes through the file modification time

Click the OK button and wait for the compilation to complete. After the compilation is completed, a prompt for successful compilation will pop up.

hot_deploy_result.png

TIP

  • Hot reloading of changed files through hot deployment is supported only after the application is attached
  • When using remote dynamic compilation, the attached application must be started through JDK, not JRE.

4.2 Single file remote compilation

The Remote Compile 'xxx' to Hot Reload button in the right-click menu can be used to hot reload a single changed file through remote dynamic compilation.

hot_compile_file_button.png

After hot deployment is completed, a prompt will pop up indicating successful compilation.

hot_deploy_result.png

TIP

  • Hot reloading of changed files through hot deployment is only supported after the application is attached
  • When using remote dynamic compilation, the attached application must be started through JDK, not JRE.