preface

The most popular hot deployment in Spring Boot is DevTools.

JRebel beats DevTools in terms of speed of loading and ease of use.

As an older development tool, JRebel really deserves a chapter.

How to break JRebel charges?

The author has written a separate article on how to activate JRebel, which you can check out if you don’t have the money: get a reverse proxy tool and play around with JRebel.

Hereby declare: the author supports the original, not bad money suggested to install an original, after all, such a good tool is worth.

What is local hot deployment?

In traditional development, code changes made during project startup are not recompiled and run, but are only implemented after the project is shut down and restarted.

Local hot deployment is the ability to sense changes to specific file code while the project is running and enable the project to take effect without restarting.

What is remote hot deployment?

The term remote hot deployment refers to the remote server. In normal development, any changes to the local code must be repackaged and uploaded to the server and then restarted. Have you ever done that? .

Remote hot deployment is the local code changes, do not need to re-package upload server restart project can take effect, local changes can automatically change the project code on the server.

Some people hear this and they’re dumbstruck. What the hell is this? And such amazing things………..

Differences between JRebel and DevTools

The comparison between the old and the young is not really comparable, and if it weren’t for JRebel, it would be the first choice of any programmer. But here are the differences:

  1. JRebelLoading speed is better thandevtools
  2. JRebel is not limited to Spring Boot projects, but can be used in any Java project.
  3. devtoolsThe hot deployment mode has limited functions. Modification in a method can implement hot deployment, but the new method or modification of method parameters does not take effect.

How do I install JRebel?

Local hot deployment only requires a JRebel plug-in in IDEA, and remote hot deployment requires a JRebel plug-in on the server, both of which were covered in the previous article, but you can check it out if you don’t: get a reverse proxy tool and play around with JRebel.

How to deploy locally?

After the JRebel plug-in is installed, enable automatic compilation in IDEA, then go to the tool panel of JRebel in IDEA and check the projects or modules required for hot deployment, as shown below:

This will generate a rebel.xml file under the project or module’s SRC /resource.

Right click on the main Boot class of Spring Boot and the option to Boot with JRebel appears, as shown below:

Of course, there is also a startup button in the upper right corner of IDEA, as shown below:

(1) Local startup and DEBUG mode startup, (2) Update button for remote hot deployment.

If the selected project or module changes, press CRTL+SHIFT+F9 to automatically recompile and load the changed part without restarting the project.

How to deploy remotely?

Remote hot deployment requires the installation and activation of JRebel on the server, as in the previous article: A reverse proxy tool to play around with JRebel.

Once activated, you need to set the password for the remote connection by executing the following command in JRebel’s root directory:

java -jar jrebel.jar -set-remote-password 123456789
Copy the code

123456789 is the remote password, which is required when IDEA is connected to the server.

After the server is successfully configured, the module of remote hot deployment is set in the panel of JRebel in IDEA, as shown below:

When checked, a rebel-remote. XML file will be generated under SRC /resource.

At this point, package the Spring Boot project as a Jar, upload it to the server, and run the following command to start the project:

nohup java -agentpath:/usr/local/jrebel/lib/libjrebel64.so  -Drebel.remoting_plugin=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9083 -jar xxx.jar &
Copy the code

The file libjrebel64.so is in JRebel’s lib directory.

-xdebug -jar -jar -xdebug -jar -jar -xdebug -jar Spring Boot also enables remote debugging.

Once the project is successfully started, the configuration on the server is complete.

At this point, you need to set up connection to the project just started in IDEA, open File-> Setting ->JRbel&XRebel->JRbel Remote Servers, as shown below:

The steps are as follows:

  1. Click on the+Add a service
  2. Fill in the information
  • server nameName any service
  • server URLFormat:http://ip:portHere,ipIs the IP address of the server,portIs the project port number.
  • The remote password is set aboveJRebelThe password123456789.
  1. Click on theOK“Is displayed.

After the above Settings are successful, click the remote deployment button in the upper right corner, button no. 2 in the picture below, the code of the started project on the server will be automatically updated so that the local modification will take effect automatically on the server side:

The JRebel Console panel will print the log information for remote hot deployment updates as shown below:

Whenever changes are made locally, clicking the remote hot deployment button automatically uploads the code to the server side and updates it in real time without restarting the project.

A pit for multi-module development

If it is multi-module development, for example, divided into API (final Jar package), Core (core package), and Service (business layer package), the API module is finally packaged and runs on the server side. The other two modules are all dependent modules, although they are checked in JRebel remote hot deployment option. But their code changes do not take effect on the server side.

How do we solve this? Simply add the other two modules to the rebel-remote. XML file under the API project. The default is as follows:


      
<rebel-remote xmlns="http://www.zeroturnaround.com/rebel/remote">
    <id>xx.xx.xx.api</id>
</rebel-remote>
Copy the code

Add the following code:


      
<rebel-remote xmlns="http://www.zeroturnaround.com/rebel/remote">
    <id>xx.xxx.xx.api</id>
    <id>xx.xx.xx.service</id>
    <id>xx.xx.xx.core</id>
</rebel-remote>
Copy the code

The < ID > tag above specifies the module’s package name.

conclusion

As the predecessor of the hot deployment world, JRebel is still the same as the old……

Hopefully this article will improve the productivity of JRebel for readers, which I did