You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为IntelliJ中Gradle+Tomcat插件配置JRebel实现热部署

Hey there! Let's get your JRebel hot-deployment up and running with your Gradle + Tomcat setup. I'll break down exactly where to modify the scripts and even share a more IDE-friendly approach since you're using IntelliJ:

1. Modify the Gradle Startup Script (Global or Wrapper)

First, the location depends on whether you're using a global Gradle installation or the Gradle Wrapper (the default for most projects):

  • Windows:

    • Global Gradle: Find bin\gradle.bat in your Gradle install directory (e.g., C:\Gradle\gradle-4.3.1\bin\gradle.bat)
    • Gradle Wrapper: Look in your project root for gradlew.bat

    Add these lines early in the script (before the Java command is executed):

    @rem Set JRebel installation path
    set REBEL_HOME=C:\path\to\your\jrebel\folder
    @rem Add JRebel agent to JVM options
    set JAVA_OPTS="-javaagent:%REBEL_HOME%\jrebel.jar %JAVA_OPTS%"
    
  • Linux/macOS:

    • Global Gradle: Find bin/gradle in your Gradle install directory (e.g., /usr/local/gradle-4.3.1/bin/gradle)
    • Gradle Wrapper: Look in your project root for gradlew

    Add these lines at the top of the script:

    # Set JRebel installation path
    export REBEL_HOME=/path/to/your/jrebel/folder
    # Add JRebel agent to JVM options
    export JAVA_OPTS="-javaagent:$REBEL_HOME/jrebel.jar $JAVA_OPTS"
    

Since you're launching Tomcat directly from IntelliJ, you don't need to mess with global scripts—configure it directly in your run/debug settings for better flexibility:

  • Open Run > Edit Configurations in IntelliJ
  • Find your Tomcat run configuration (it's tied to the tomcatRun or tomcatWarRun Gradle task from the bmuschko plugin)
  • Switch to the Environment Variables tab:
    • Click the + button, add REBEL_HOME as the name, and paste your JRebel install path as the value
  • Switch to the VM options field (under the Configuration tab) and add:
    -javaagent:$REBEL_HOME/jrebel.jar
    
  • Save the configuration and restart your Tomcat instance
3. Verify JRebel is Working

After starting Tomcat, check the console output. You should see logs like:

JRebel: Starting up...
JRebel: Monitoring changes in [path/to/your/src/main/webapp]

If you see these lines, go ahead and modify a file in your webapp folder—refresh your browser, and the changes should show up immediately without a full restart.

Quick Check for rebel.xml

Make sure your rebel.xml in build/classes/main correctly points to your webapp directory. A basic valid config looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://www.zeroturnaround.com"
             xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
  <web>
    <link target="/">
      <dir name="src/main/webapp"/>
    </link>
  </web>
</application>

内容的提问来源于stack exchange,提问作者Al Phaba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:38:45