JRebel熱部署迅速上手

一、官網

IDEA 中使用教程:https://zeroturnaround.com/so...
Maven工程中使用JRebel:http://manuals.zeroturnaround...

二、使用

1. IDEA 中安裝JRebel插件

File -> Settings -> Plugins -> Browse repositories 中 搜索 JRebel,安裝 JRebel for IntelliJ 插件即可。

破解可以參考這篇文章:https://blog.csdn.net/liusuih...

2. 配置JRebel Maven插件

官方文檔:https://manuals.zeroturnaroun...

JRebel Maven插件的目的是在Maven構建期間爲您的項目生成rebel.xml文件。

對於Maven項目 特別是在多模塊項目的情況下 使用JRebel Maven插件生成rebel.xml配置文件很方便。將以下代碼段添加到您的父級pom.xml。該rebel.xml配置文件可以在你的Maven項目的每個單獨的子模塊產生。

<plugin>
    <groupId>org.zeroturnaround</groupId>
    <artifactId>jrebel-maven-plugin</artifactId>
    <version>1.1.8</version>
    <configuration>
        <!-- 將配置的資源目錄也添加到rebel.xml中 -->
        <addResourcesDirToRebelXml>true</addResourcesDirToRebelXml>
        <!--如果設置爲true,則生成的rebel.xml將在構建期間在控制檯中打印出來,可以立即看到生成的內容。默認爲false-->
        <showGenerated>true</showGenerated>
        <!-- 每次都生成新的rebel.xml。如果爲false,只在rebel.xml和pom.xml的時間戳不相同的時候,重新生成rebel.xml。默認爲false -->
        <!--<alwaysGenerate>true</alwaysGenerate>-->
        <!-- 在單個項目中處理多個模塊時,您可以選擇跳過爲特定模塊生成rebel.xml。 只需將以下內容添加到他們的pom.xml中即可 -->
        <!--<skip>true</skip>-->
        <!-- 如果工程師自己自定義的package,則需要主動設置爲 jar 或者 war -->
        <!--<packaging>war</packaging>-->
    </configuration>
    <executions>
        <execution>
            <id>generate-rebel-xml</id>
            <phase>process-resources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

配置結束後執行命令mvn jrebel:generate

3. 啓動

啓動時使用 JRebel 按鈕來Run和Debug,會自動在 resources 文件夾中生成rebel.xml文件,文件中配置了Jrebel熱加載的時候需要追蹤的文件路徑及web配置。比如自己需要主動加入 shop-model 模塊的路徑

<?xml version="1.0" encoding="UTF-8"?>

<!--
  This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
  Refer to https://manuals.zeroturnaround.com/jrebel/standalone/config.html for more information.
-->
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">

    <classpath>
        <dir name="C:/workspace/song/shop/shop-web/target/classes">
        </dir>
        <dir name="C:/workspace/song/shop/shop-model/target/classes">
        </dir>
    </classpath>

    <web>
        <link target="/">
            <dir name="C:/workspace/song/shop/shop-web/src/main/webapp">
            </dir>
        </link>
    </web>

</application>

4. 最後的配置

如果不做下面的配置,則需要手動編譯纔會觸發熱部署(spring boot devtools一樣的問題):

  1. 到設置裏將 project automatically 勾選上:File -> Settings -> Build,… -> Compiler ,勾選 Build project automatically
  2. Intellij IEDA 使用 ctrl + shift + alt + / 快捷鍵選擇 Registry... ,勾選 compiler.automake.allow.when.app.running

5. 推薦用法

一般修改java文件後,會自動編譯的。但是一般自己主動觸發編譯會更可控一些:

Ctrl + Shift + F9 編譯當前文件 或者 右鍵-> Recompile ....java

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章