Swagger 生成的代码不断被 JRebel 删除和重新上传 - 没完没了

Swagger generated code keeps being deleted and re-uploaded by JRebel - endlessly

我有一个从 Swagger jaxrs-resteasy 生成的 Wildfly Rest 服务。该项目是来自 Jetbrains IntelliJ Idea IDE 的 Maven,我也是 运行 jrebel。整个设置的一切都很好,除了来自 src/gen/java 路径的所有代码(生成的代码)不断被 JRebel 删除和上传。我是否遗漏了 rebel.xml 文件中的某些内容以使其停止执行此操作?

JRebel console 不断循环以下信息,我担心用电量很快就会足够给 Tesla 充电...

[2017-05-08 16:10:14] Synchronization took 189 ms in total.
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Connecting to server to sync project
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/RestApplication.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/model/TaxDataResponse.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/StringUtil.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/ApiOriginFilter.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/ApiResponseMessage.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/AuthenticateApiService.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/RFC3339DateFormat.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/model/UserDefined.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/model/AuthenticationRequest.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/NotFoundException.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/TaxApiService.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/model/ChargeItemType.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/ApiException.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Deleting remote resource 'io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:21] [Project RESServices, server Local Wildfly] Upload succeeded in 147 ms. Transaction took 173 ms.
[2017-05-08 16:10:21] Synchronization took 205 ms in total.
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Connecting to server to sync project
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/RestApplication.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/model/UserDefined.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/RFC3339DateFormat.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/model/TaxDataResponse.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/StringUtil.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/ApiOriginFilter.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/ApiResponseMessage.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/AuthenticateApiService.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/NotFoundException.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/model/AuthenticationRequest.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/TaxApiService.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/model/ChargeItemType.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/ApiException.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Uploading resource 'target/classes/io/swagger/api/JacksonConfig.class'
[2017-05-08 16:10:24] [Project RESServices, server Local Wildfly] Upload succeeded in 178 ms. Transaction took 197 ms.
[2017-05-08 16:10:24] Synchronization took 197 ms in total.

我怀疑问题出在 rebel.xml 中,尽管您可以首先从一个非常简单的 rebel.xml[=36= 开始] 然后从那里继续验证,在你的情况下,以下应该是一个好的开始:

<?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="/absolute/path/to/project/target/classes">
        </dir>
    </classpath>
</application>

最初 JRebel 执行一次同步,其中删除所有旧文件并上传新文件,之后 JRebel 开始监视本地构建目录 (../target/classes/) 中的所有文件更改并将触发同步检测到时间戳更改后的事件。如果文件 md5 hash 与之前不同,则上传。

此外,JRebel 还可以监视其他资源文件(Web 文件、属性 文件等),这些文件可以在 rebel.xml 中指定。

很难说到底发生了什么,但我的猜测是由于某种原因,生成的文件经常被重新编译(可能是自动生成的时间戳)并且 JRebel 检测到这些文件的哈希值发生了变化。您可以手动检查文件哈希并验证是否可能是这种情况。

如果由于某种原因 IDEA 不断地重新编译和更改 .class 文件,您可以禁用 JRebel 在每次构建后自动同步。在这种情况下,您必须在需要时手动与远程服务器同步。

Help > JRebel > Configuration > Remote Servers > "Synchronize on build"

为了弄清楚确切原因,请在{user.home}/.[=44=中添加rebel.ide.log=trace ].properties,重启IDE并重现问题,日志将生成为jrebel-intellij.log。将其发送至 support@zeroturnaround.com,他们将能够为您提供更多详细信息。