java - JRebel不会在intellij中热部署带有嵌入式tomcat的源文件

标签 java intellij-idea gradle jrebel

我有以下项目结构

project-root
--core
---build.gradle
---project.gradle
--web
---build.gradle
---project.gradle

我将 jRebel 配置为使用 gradle 运行,因此我可以使用命令 gradle tomcatRun 启动嵌入式 tomcat 8

这显示了 jrebel 的日志输出,我的应用程序在嵌入式服务器上启动,但当我更改 java 文件时没有热部署。

使用 IntelliJ JRebel 插件,我为每个项目根项目、核心项目和 Web 项目创建了rebel.xml 文件。另外,我还在 web 项目中的 web/build/classes/main 文件夹中添加了一个rebel.xml,如here所述。

通常情况下,jrebel 应该在启动时显示它正在监视某些文件夹,但我的网站上并非如此,所以我猜我的配置有问题

这里是rebel.xml 文件

project-root(路径 c:/project-root/rebel.xml)

     <?xml xsd....">
        <classpath>
            <dir name="c:/project-root/out/production/classes">
            </dir>
        </classpath>
     </application>

核心(路径c:/project-root/core/src/main/resources/rebel.xml)

    <?xml version="1.0" encoding="UTF-8"?>
    <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:/project-root/core/out/production/resources">
            </dir>
            <dir name="c:/project-root/core/out/production/classes">
            </dir>
        </classpath>
    </application>

web(路径 c:/project-root/web/src/main/resources/rebel.xml)

    <?xml version="1.0" encoding="UTF-8"?>
    <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:/project-root/web/out/production/classes">
        </dir>
    </classpath>
    </application>

web(路径 c:/project-root/web/build/classes/main/rebel.xml)

    <?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">
    <classpath>
        <dir name="c:/project-root/web/build/classes/main">
        </dir>
    </classpath>
    <web>
        <link target="/">
            <dir name="c:/project-root/web/src/main/webapp">
            </dir>
        </link>
    </web>
    </application>

为了将 jrebel 附加到我的 gradle,我在启动 gradle tomcatRun 之前执行了以下批处理调用

set REBEL_HOME=C:\Users\myuser\.IdeaIC2017.3\config\plugins\jr-ide-idea\lib\jrebel6
set JAVA_OPTS="-agentpath:%REBEL_HOME%\lib\jrebel64.dll"

然后调用 gradlew tomcatRun 启动 tomcat 和 jrebel

    gradlew tomcatRun
    2018-01-09 10:24:09 JRebel:  Starting logging to file: C:\Users\myuser\.jrebel\jrebel.log
    2018-01-09 10:24:09 JRebel:
    2018-01-09 10:24:09 JRebel:  #############################################################
    2018-01-09 10:24:09 JRebel:
    2018-01-09 10:24:09 JRebel:  JRebel Agent 7.1.3 (201711301108)
    2018-01-09 10:24:09 JRebel:  (c) Copyright ZeroTurnaround AS, Estonia, Tartu.
    2018-01-09 10:24:09 JRebel:
    2018-01-09 10:24:09 JRebel:  Over the last 2 days JRebel prevented
    2018-01-09 10:24:09 JRebel:  at least 0 redeploys/restarts saving you about 0 hours.

但是当我更改一些源文件时,jrebel 没有检测到任何内容,当我手动调用 gradlewcompileJava 时也是如此

最佳答案

我认为问题在于 JRebel 没有附加到运行嵌入式 Tomcat 服务器的实际进程。相反,它会附加到 Gradle 的包装器进程。尝试通过 org.gradle.jvmargs 选项附加 JRebel 的 JVM 参数。

gradle tomcatRun -Dorg.gradle.jvmargs="-agentpath:/path/to/jrebel/lib/libjrebel64.so"

此外,由于 tomcatRun 任务使用分解部署,因此不需要 rebel.xml 文件。这是因为构建输出目录与部署目录相同,并且 JRebel 会自动拾取该目录中所做的更改并重新加载。

确保还编译使用 gradlecompileJava 命令所做的更改。

我亲自尝试了一下,效果不错。虽然它不会将 JRebel 横幅输出到控制台输出,但它确实会让您知道类文件何时重新加载。

关于java - JRebel不会在intellij中热部署带有嵌入式tomcat的源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48158667/

相关文章:

java - 使用 MockServletContext 进行单元测试

java - 将 IntelliJ IDEA 项目转换为 Eclipse

java - 使用 Intellij Application run 和 gradle 4.2.1 时的单个编译输出目录

java - 无法运行Maven和Spring Boot打包的可执行jar

oauth2 的 java Rest jersey 重定向不起作用

java - 如何使用登录凭据和 ssl 证书在 JAVA 中进行基本的 http 身份验证?

java - 如何在插件操作类中获取当前文件名

android - 是否可以同时在 iOS 和 Android 模拟器上启用热重载?

java - 将应用程序正确划分为模块

gradle - 如何在 gradle 中插入自定义任务