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.
-XXaltjvm=dcevm -javaagent:${agentPath}/debug-tools-agent.jar=${conf}
[Java 11] Add the following JVM parameters when starting.
-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.
-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.jarconf
is the configuration information passed to the agent, in the format ofkey1=value1,key2=value2
2.2 Optional configuration
Optional key | Meaning | Value | Example |
---|---|---|---|
hotswap | Whether to enable hot reload/hot deployment | true: Enable false: Disable | true |
server | Whether to start the server for client connections | true: Enable false: Disable | true |
tcpPort | TCP port to listen to (valid only when server=true) | Available ports | 12345 |
httpPort | HTTP port to listen to (valid only when server=true) | Available ports | 22222 |
printSql | Whether to print the executed SQL statement | true: Enable false: Disable | true |
propertiesFilePath | External configuration file path | Configuration file address | /etc/debug-tools/conf/debug-tools-agent.properties |
propertiesFilePath configuration
key | meaning | default value |
---|---|---|
hotswap | whether to enable hot reload/hot deployment (same as above) | true |
server | whether to start the server for client connection (same as above) | true |
tcpPort | TCP port to listen on (valid only when server=true) (same as above) | default, start from 12345 to find available ports |
httpPort | HTTP port to listen on (valid only when server=true) (same as above) | default, start from 22222 to find available ports |
lombokJarPath | lombok.jar path, if lombok is used during remote dynamic compilation, it needs to be specified to compile (same as above) | - |
printSql | whether to print the executed SQL statement | false |
includedClassLoaderPatterns | ClassLoader to initialize hot reload/hot deployment. Only one of the excludedClassLoaderPatterns can be configured at the same time | - |
excludedClassLoaderPatterns | The ClassLoader to be excluded from initialization reloading/hot deployment. Only one can be configured at the same time with includedClassLoaderPatterns | - |
pluginPackages | Scan plugins written on other paths, multiple paths are separated by commas | - |
extraClasspath | MacOS/Linux loads extended class file path | /var/tmp/debug-tools/classes |
extraClasspathWin | Windows loads extended class file path | c:/var/tmp/debug-tools/classes |
watchResources | MacOS/Linux monitor resource path | /var/tmp/debug-tools/resources |
watchResourcesWin | Windows monitor resource path | c:/var/tmp/debug-tools/resources |
spring.basePackagePrefix | Spring base package prefix, multiple paths are separated by commas | - |
disabledPlugins | Disabled plugins, multiple commas are separated | - |
autoHotswap | Whether 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.port | JPDA 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
to fill in the remote address.
Enter host, tcpPort and httpPort, and click the Save & Connent
button to connect the remote application.
After successfully attaching the application, DebugTools will display the attachment status.
R
: indicates that the application is a remote application, andL
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.
4. Using hot reload
4.1 Multiple files
Click the button to wake up the main page.
After selecting the file to be deployed
Compiler Type
: file compilation methodLocal Intellij Idea
: compile the changed files through the idea compilerRemote Attach Application
: remote dynamic compilation of the changed files through the attached application
Select Type
: file selection methodJava
: changed java filesResources
: 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.
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.
After hot deployment is completed, a prompt will pop up indicating successful compilation.
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.