In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to understand the simple and fast java hot deployment, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Introduction to Arthas Hot Swap plug-in
Introduction
Hot deployment is a powerful tool to help developers improve their efficiency, if your development language is java, the development environment is a remote server, and the debug port of the remote server is limited, then you may not be able to achieve hot deployment through debug HotSwap, then the IntelliJ IDEA plug-in introduced in this article can help you achieve hot deployment on the remote server, and the operation is simple and fast.
In this paper, the hot deployment plug-in (Arthas Hot Swap) is based on the Arthas redefine command, using this plug-in for remote hot deployment does not need any configuration, does not need to use the debug port, and only needs a few simple actions. GitHub address: https://github.com/xxxtai/arthas-hotswap
Usage
IntelliJ IDEA installation plug-in "Arthas Hot Swap", download the installation package from gitHub Releases
Hot deployment uses class files, so you need to use "mvn compile" to compile related projects first. Later, you can use IDEA's Recompile to compile a single file to save compilation time.
Select the java source file or class file that needs hot deployment, right-click on the class name or method name, and select "Swap this class" of "Arthas Hot Swap". After the plug-in background executes successfully, the commands required for hot deployment will be copied to the pasteboard.
Log in to the remote server, paste the hot deployment command and execute it, and the hot deployment is complete, and the machine is running the latest class. The machine executes a hot deployment command for the first time and may fail. Try again.
Step 1: select the Arthas Hot Swap plug-in option
Step 2: log in to the remote server to paste the command and execute
Step 3: hot deployment is completed and hot deployment is successful
Limitations of hot deployment
Because it is hot deployment based on Arthas's redefine command, and redefine is based on Instrumentation API's hot deployment, it has the same limitation as IDEA's debug HotSwap. The restrictions are as follows: the class name and method name cannot be modified, the class property name cannot be modified, the class property cannot be added, and non-static methods cannot be added. Because this plug-in is temporarily unable to get the class file of the inner class, it is not supported to modify the inner class for the time being.
Principle of Arthas Hot Swap plug-in
Arthas is Alibaba's open source Java code diagnosis tool. Arthas's redefine command is based on hot deployment implemented by Instrumentation API, so it has the same limitations as HotSwap hot deployment. Arthas's redefine command actually wraps the Instrumentation API's redefineClasses method and provides it to the user, so we can use our imagination according to the redefine command to achieve hot deployment.
Arthas official documentation recommends using a series of commands such as jad/mc/redefine to implement class remote hot replacement. The process is probably as follows: jad command decompilates the old class-> vim edits source code-> mc command compiles source code-> redefine hot replacement class. There are two problems with this approach: one is that it is too troublesome, and the other is that mc compilation will fail. If you can do so, modify the code locally and upload the class file to the remote server after compilation, and then use the redefine command to hot replace class. Therefore, the official document also recommends that you first convert the class binary file to base64 encoding, then copy and paste it to a remote server, convert the base64 encoding into a class file, and finally, use redefine for hot replacement. With so much trouble, we might as well redeploy. So the redefine command is more chicken rib.
The biggest problem with the hot replacement method officially recommended by Arthas is that the process of uploading class files to a remote server for hot replacement is too troublesome, so why not leave these troublesome and fixed processes to the machine to do. Therefore, the "Arthas Hot Swap" plug-in recommended in this article is necessary, which is to improve the efficiency of hot replacement with Arthas. A few simple actions can hot replace a class file, which can solve 80% of the hot deployment requirements in the development process, and the remaining 20% can be solved by redeployment.
Arthas Hot Swap plug-in execution process
Find the class file according to the source file selected by the user, and find it under the / target/classes path by default. You can also select the class file directly.
Use AES-128 to encrypt class files and output base64 encoding
Upload the encrypted class file to oss and return the oss access address
The script that needs to be executed for rendering hot deployment. The rendered script is also uploaded to oss and returned to the oss access address.
Assemble hot deployment commands and automatically copy them to the pasteboard.
Remote server hot deployment execution process
Log in to the remote server, paste the hot deployment command and execute
Download hot deployment scripts and execute hot deployment scripts
Create a Workspac
Check if openssl is installed. If not, install it.
Download AES-128 encrypted class file
Decrypt the class binary file using openssl enc
Install arthas scripted
Create a pipeline to communicate with arthas and start arthas
Arthas selects the java process. The first process is selected by default.
Arthas executes redefine command to hot replace class file
Print the hot replacement results.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.