从Eclipse迁移至IntelliJ,如何实现WebSphere下.xhtml文件热交换?
解决IntelliJ中WebSphere下XHTML/Spring Web Flow资源热交换问题
我之前从Eclipse迁到IntelliJ时,也碰到过一模一样的WebSphere热部署痛点——改了xhtml或者Spring Web Flow的xml文件,刷新浏览器死活看不到变化,要么就得重启服务器,耗时又麻烦。给你几个亲测有效的方案,一步步来调整:
1. 调整IntelliJ服务器的自动更新策略
首先检查WebSphere服务器的配置:
- 打开Run/Debug Configurations,找到你的WebSphere服务器配置
- 切换到「Server」标签页,找到「On frame deactivation」选项,选择「Update resources」
- 同时确认「On 'Update' action」设置为「Update resources」(不要选带classes的选项,避免触发类加载重启)
这样当你切换出IntelliJ窗口(比如切到浏览器)时,IntelliJ会自动把修改的资源同步到服务器,不用手动点任何按钮。
2. 确保资源被正确映射到EAR exploded构件
IntelliJ的ear exploded构件默认可能没有把所有资源都设置为自动同步,需要调整:
- 打开「File → Project Structure → Artifacts」
- 找到你的「project:ear exploded」构件,展开里面的Web模块(比如你的war模块)
- 检查xhtml、xml这些资源文件的部署设置:右键点击资源所在的目录,选择「Put into Output Root」,确保它们会被直接复制到服务器的部署目录,而不是需要重新构建整个EAR
- 另外,在模块的「Settings → Modules → 你的Web模块 → Paths」里,确认「Output directory」和「Test output directory」是指向正确的 exploded 路径
3. 开启IntelliJ的自动编译功能
这个是关键,让IntelliJ在你修改资源后自动同步:
- 打开「Settings → Build, Execution, Deployment → Compiler」,勾选「Build project automatically」
- 接着打开「Settings → Advanced Settings」,找到「Allow auto-make to start even if developed application is currently running」并勾选
这样修改xhtml或xml文件后,IntelliJ会自动把变更同步到服务器的exploded目录,WebSphere就能立即识别到。
4. 调整WebSphere自身的热部署设置
有时候问题出在WebSphere服务器本身,需要开启开发模式:
- 登录WebSphere的管理控制台(默认是
http://localhost:9060/ibm/console) - 找到你的应用,进入「Application details」页面,在「Class loading and update detection」部分:
- 设置「Reload interval」为1(表示服务器每秒检查一次资源变化)
- 勾选「Run in development mode」,允许资源热替换
- 确保「Update application」的策略设置为「Update without restart」
5. Spring Web Flow XML的特殊处理
对于Spring Web Flow的配置文件,除了上面的同步设置,还可以在Spring配置里开启热刷新:
- 在你的Web Flow配置类或xml中,设置
FlowBuilderServices的refreshResources属性为true,比如:
@Bean public FlowBuilderServices flowBuilderServices() { return new FlowBuilderServicesBuilder() .setRefreshResources(true) .build(); }
这样Web Flow会自动检测配置文件的变化,不用重启应用。
另外,你之前提到的「Run → Update Application → Update Resources」会重启服务器,大概率是因为WebSphere的默认更新策略设置不对,按照上面第4步调整后,应该只会同步资源而不会重启。
内容的提问来源于stack exchange,提问作者Vytautas Šerėnas




