JRebel 不监听或重新加载 src/main/resources 目录中的更改,从而导致读取此类文件返回缓存的无效值。
这正常吗?
确保该目录列在随应用程序部署的 rebel.xml 配置文件中。如果您的rebel.xml是使用Maven的JRebel插件生成的,那么只需确保指定您希望将资源目录包含在配置中:
<addResourcesDirToRebelXml>true</addResourcesDirToRebelXml>
如果您使用的是 IntelliJ IDEA,并且没有看到应用于资源的更改,则您可能尚未将 IDE 配置为将文件从资源目录复制到目标目录。或者将资源目录标记为“资源”目录(右键单击项目树中的文件夹 -> 将目录标记为...)
我遇到了同样的问题,阅读手册后我找到了适合我的解决方案。
我正在使用带有 Spring 3 的 JSF 项目,带有 netbeans 并通过 IDE 运行 jrebel
请注意,这些评论是我之前尝试过的,但这并不意味着不起作用。
这里重要的是将资源路径添加到类路径中,并消除 jrebel 自动放入 Web 节点中的链接标记。
rebel.xml:
<application generated-by="netbeans"
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="/path_to_project_root/target/classes"></dir>-->
<dirset dir="/path_to_project_root/">
<include name="**/target/classes"/>
<include name="**/src/main/resources"/>
</dirset>
</classpath>
<web>
<!--<link target="/">-->
<dir name="/path_to_project_root/src/main/webapp"></dir>
<dir name="/path_to_project_root/src/main/resources"></dir>
<!--</link>-->
</web>
</application>
我还在 pom.xml 中配置了插件,将属性 addResourcesDirToRebelXml 设置为 true
pom.xml:
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<version>1.1.7</version>
<configuration>
<addResourcesDirToRebelXml>true</addResourcesDirToRebelXml>
</configuration>
<executions>
<execution>
<id>generate-rebel-xml</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
来源:https://manuals.zeroturnaround.com/jrebel/standalone/advanced-config.html
如果您使用 IntelliJ IDEA,请尝试“Build”选项卡下的“Make Project”或按 Ctrl+F9。
确保您的项目在 eclipse 中没有任何编译错误。
还要检查您的 JDK 合规性。我的版本错误,我的目标/类文件未更新。
如果目标/类内容未更新,jrebel 将不会看到任何更改。
我用过类似的东西,它对我有用。 JRebel插件需要在IDEA上安装或者你可以在pom.xml中使用插件
注1:rebel.xml文件是IDEA上的JRebel插件自动生成到src/main/resources中的,所以不需要在pom.xml中添加jrebel插件
注意2:不要忘记在路径中保留斜杠,而不是反斜杠! ;)
<?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://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
<classpath>
<dir name="C:/myWorkspace/myWar/target/classes"></dir>
</classpath>
<web>
<link target="/">
<dir name="C:/myWorkspace/myWar/src/main/webapp"></dir>
</link>
</web>
</application>
简单地,将根路径添加到
rebel.xml
内的classpath
,命名为dir
,并具有精确的路径。
例如我的项目在java目录下有类和资源文件,所以我设置为:
<?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_3.xsd">
<id>$your project id$</id>
<classpath>
<dir name="$yourProjectPath$/out/production/resources">
</dir>
<dir name="$yourProjectPath$/src/java/">
</dir>
<dir name="$yourProjectPath$/out/production/classes">
</dir>
</classpath>
</application>