1 overview
Hot deployment, for Java applications, means updating Java class files at run time. IDEA can be used for local/remote hot deployment using the built-in Spring Boot hot deployment or JRebel can be used for local/remote hot deployment with the JRebel and XRebel for IntelliJ plug-in installed. This article will introduce these two ways to carry out hot deployment, which should be the most detailed article on IDEA hot deployment that can be found on the Internet. I believe that after reading this article, the development efficiency will be greatly improved, and there is no need to manually type JAR/WAR package and upload it to the server and a series of tedious operations.
2 the environment
- IDE: IntelliJ IDEA 2019.3.1
- Local Tomcat: 9.0.30
- JRebel and XRebel for IntelliJ:2020.2.0
- Server :CentOS 8.1.1911
- Tomcat server: 9.0.33
3 IDEA hot deployment
3.1 Engineering
3.1.1 New Construction Project
Create a new Spring Boot project to test the hot deployment.
3.1.2 Test files
Create a new Controller that responds to the Get request:
3.2 Internal Tomcat Hot Deployment
Spring Boot has a Tomcat embedded and can be used directly for hot deployment.
3.2.1 IDEA set
Build Project Automatically in Compiler
3.2.2 test
IDEA contains an HTTP client that can send an HTTP Request and create an HTTP Request:
3.3 External Tomcat Hot Deployment
Since the related Settings of IDEA have been configured, it will not be repeated here. The ones that are not configured are configured in the above way, and then an external Tomcat configuration needs to be added.
3.3.1 External Tomcat Configuration
An external Tomcat running configuration needs to be added:
3.3.2 rainfall distribution on 10-12 test
Note that external Tomcat hot deployment cannot be Run with Shift+F10, as internal Tomcat hot deployment can be Run with Shift+F9:
3.4 Remote Tomcat Hot Deployment
Remote Tomcat hot deployment is a hassle, with many details. A port error is a bunch of exceptions, so please be patient and take a look. Three steps are required: Configure Tomcat for the server, configure server configuration for IDEA, and configure Tomcat running for IDEA. Finally, test.
3.4.1 Tomcat Settings for the Server
There are four ports to handle :Tomcat HTTP port,JMX port,RMI port, and debug port. The HTTP port is often referred to as the Tomcat port. The browser type http://ip:port to access the default Tomcat home page, set in server.xml, this is at line 69, using the default 8080.
CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.rmi.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=ip - agentlib: JDWP = transport = dt_socket, address = 0.0.0.0:12345, suspend = n, server = y"
Copy the code
JMX and RMI ports are set to be the same as each other, and 12345 after address is the debugging port and can be set as required. IP is the IP address of the server
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Copy the code
These two lines indicate that authentication is not required when connecting to Tomcat without SSL or using a JMX client. Be sure to add
-Dcom.sun.management.jmxremote.rmi.port=8888
Copy the code
This RMI port, which is not included in many articles, causes the deployment to fail. Finally change the execution permission and start Tomcat:
chmod 750 setenv.sh
./startup.sh
Copy the code
You can check port listening:
netstart -ano | grep -E "8080 | 8888 | 12345"
Copy the code
3.4.2 Server Settings in IDEA
To create an SFTP deployment:
Tomcat Settings in 3.4.3 IDEA
Create a Tomcat Remote:
3.4.4 test
You need to Run in Debug mode (Shift+F9), not Run(Shift+F10):
4 JRebel hot deployment
4.1 introduction of equal
4.2 installation
From the Plugins installation in the Settings, search for:
Stamp here
4.3 Internal Tomcat Hot Deployment
Internal Tocmat hot deployment is very simple, after selecting the SpringBoot Run configuration, just click Rebel Run:
4.4 External Tomcat Hot Deployment
Once external Tomcat is configured, as in 3.3 above, Rebel Run is a one-click option. Ensure that the port is not occupied.
4.5 Remote Tomcat Hot Deployment
Remote Tomcat hot deployments using JRebel need to be packaged and uploaded before they can be hot deployed.
4.5.1 Uploading a Package
Before hot deployment, you need to manually pack:
4.5.2 Creating a Script
4.5.3 Adding a Remote Server
java -jar xxx.jar -set-remote-password PASSWORD
Copy the code
), select Server Authentication and fill in the password. If Tomcat has set the access password (see the setting method here), you need to check HTTP Basic Authentication and enter the user name and password:
4.5.4 test
Then, open JRebel and select the project to deploy:
5 Appendix: JAR packaging
Because Tomcat is embedded in Spring Boot, it can be used as a JAR package to avoid a series of tedious Tomcat configurations, including directory mappings, ports, and so on. Change the <packing> in POM.xml to the original war packing form:
java -jar demo.jar
Copy the code
If there is no problem, you can upload it to the server, or you can use hot deployment. Note that Tomcat and JRebel will need to modify their configurations, but I won’t go into details.
If you think the article looks good, please like it.
At the same time, welcome to pay attention to wechat public number: Lingzhi Road.