昨天我从Eclipse切换到IntelliJ IDEA。

我也在WebSphere Server 7中使用JRebel。

现在一切似乎都运行得很好,除了当我修改一个Java文件并点击保存时,IntelliJ不会重新编译文件,以便JRebel拾取它。

Eclipse的“自动构建”特性解决了这个问题。

在IntelliJ IDEA中,我必须按CTRL+SHIFT+9来重新编译JRebel的相关类。如果跨两个文件进行更改,我必须在每个文件上都这样做,因为IntelliJ使用了保存所有机制,很难知道手动重新编译什么,我也不感兴趣。

难道没有办法让IntelliJ自己来做这个吗?


当前回答

我设法用宏来解决这个问题。

我开始录制一个宏:

点击编辑-宏-开始宏录制 单击“文件-全部保存” 单击“生成-制作项目” 单击编辑-宏-停止宏记录

命名一些有用的东西,比如“SaveAndMake”。

现在只需删除保存所有键绑定,并添加相同的键绑定到您的宏!

所以现在,每次我保存,它保存并进行脏编译,jRebel现在正确地检测所有更改。

其他回答

我也有同样的问题。 我使用的是“省电模式”,它可以防止增量编译和显示编译错误。

请遵循以下两个步骤:

1 -从编译器中启用Automake

按:ctrl + shift + A(适用于Mac⌘+ shift + A) 类型:自动制作项目 冲击:输入 启用自动制作项目功能

2 -在应用程序运行时启用Automake

按:ctrl + shift + A(适用于Mac⌘+ shift + A) 类型:注册表 找到关键编译器. autommake .allow.when.app.running并启用它或单击旁边的复选框

注意:现在重新启动您的应用程序:)

注意:这也应该允许使用spring boot devtools实时重载。

在我的maven项目中,唯一受此影响的是在单元测试的运行配置中添加“test-compile”目标。令人难以置信的笨拙解决方案,但它有效。

更新

对于IntelliJ IDEA 12+版本,如果我们使用外部编译器选项,我们可以自动构建编辑过的源代码。唯一需要做的就是勾选位于“编译器”设置下的“自动构建项目”选项:

此外,如果你想在应用程序运行时热部署,或者如果你使用spring boot devtools,你也应该从注册表中启用compiler. autommake .allow.when.app.running。这将自动编译您的更改。

对于大于2021.2的版本,我们需要勾选“即使开发应用程序正在运行,也允许自动启动”选项:

对于2021.2之前的版本:

使用Ctrl+Shift+A(或Mac上的⌘+Shift+A)键入Registry,一旦注册表窗口打开,找到并启用compiler. autommake .allow.when.app.running,参见这里:


For versions older than 12, you can use the *EclipseMode* plugin to make IDEA automatically compile the saved files.

有关更多提示,请参阅“从Eclipse迁移到IntelliJ IDEA”指南。

警告

Eclipse模式插件已经过时,并且与最近的IDEA 12+版本不兼容。如果你安装它,IDE将挂起每一个文件更改,并将响应极慢。


IntelliJ IDEA不使用自动构建,它在运行中检测错误,而不是通过编译器。类似于Eclipse模式将在IDEA 12中可用:

使用Build | Make,它调用增量的Make过程,只编译更改的和依赖的文件(它非常快)。

还有一个常见问题解答条目可能会有所帮助。

Update on the automatic make feature: When run/debug configuration is running, Make project automatically has no effect. Classes on disk will change only on Build | Make. It's the core design decision as in our opinion class changes on disk should be always under user's control. Automatic make is not the copycat of Eclipse feature, it works differently and it's main purpose is to save time waiting for the classes to be ready when they are really needed (before running the app or tests). Automatic make doesn't replace the explicit compilation that you still need to trigger like in the case described in this question. If you are looking for different behavior, EclipseMode plug-in linked in the FAQ above would be a better choice.