18

Back in December I switched from Eclipse to IntelliJ IDEA but within a couple of days I switched back. Today I tried IntelliJ again and basically I have only one issue left.

The issue is I want to compile Java classes on saving. The reason is I'm using JRebel which will pick up the new class. I don't want to hit +F9 every time to compile the changed class.

I read about the EclipseModel plugin but this does not seem to work (anymore) as can be read in the comments on the plugin's page: http://plugins.jetbrains.com/plugin/?id=3822

I also tried the "Make project automatically" but this compiles ALL classes and not only the changed class. This is only not more time consuming it will also cause JRebel to reload all classes.

Any suggestions?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Marcel Overdijk
  • 11,041
  • 17
  • 71
  • 110
  • 2
    In addition to Anton's answer check [my answer](http://stackoverflow.com/a/12744437/104891) explaining why automatic compilation is disabled when there is an active run configuration. See also the [explanation from the developer](http://devnet.jetbrains.com/message/5473042) in the forum. – CrazyCoder Jan 31 '13 at 23:57

4 Answers4

17

I ended up creating a Macro which does the Save and the Make Build. I then assigned the Ctrl+S shortcut to this Macro and then it works fine.

Marcel Overdijk
  • 11,041
  • 17
  • 71
  • 110
  • 13
    How, please give details :) – Aamir Afridi Apr 03 '13 at 11:40
  • 7
    @AamirAfridi You need to record a macro for the two actions (File -> Save All and Build -> Make Project) as explain here https://www.jetbrains.com/idea/help/recording-macros.html and then you need to assign the CTRL + S keyboard shortcut to that macro as explain here: https://www.jetbrains.com/idea/help/binding-macros-with-keyboard-shortcuts.html (When prompted for conflict just press "Remove" button to deassign the CTRL + S shortcut from the previous action) – Alex Bitek Jun 23 '15 at 15:24
  • @MnemonicFlow hahah you replied after like 2 years. Yes I figured that out. Thanks :) – Aamir Afridi Jun 24 '15 at 12:12
5

What if you just remap the keys from Ctrl+F9 to Ctrl+S? Basically you will just keep up with the habit of pressing Ctrl+S since you do that in Eclipse - just a matter of pressing a different key in IntelliJ.

IntelliJ IDEA 12 indeed comes with out-of-process compiler which compiles the project classes automatically, but it seems to be unpredictable - you might refresh the page and the class is not yet compiled. So in the scenario with JRebel the off-process compilation is no use, unfortunately.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Anton Arhipov
  • 6,479
  • 1
  • 35
  • 43
  • I tried this but it doesn't work. As soon as I add Ctrl+S keymapping to Make Project, Ctrl+S does not do anything anymore, not even saving the file itself. When I remove the keymapping Ctrl+S does at least work for saving again. – Marcel Overdijk Feb 01 '13 at 12:00
  • I did some further testing and the Ctrl+S seems to work for saving, but not for Make Project. Does IntelliJ support having 1 shortcut (Ctrl+S) for multiple Actions (Save All + Make Project)? – Marcel Overdijk Feb 01 '13 at 13:06
  • 1
    Normally I wouldn't use Ctrl+S in IntelliJ at - it saves files automatically for me. One option could be also to create a simple plugin that intercepts the Save action (http://arhipov.blogspot.com/2011/04/code-snippet-intercepting-on-save.html) and invokes the compier. But in general, I found that trying to adopt the habits that come from Eclipse to the new environment doesn't really make sense - it will only take you some days to get used to pressing Ctrl+F9 instead for Ctrl+S. After a while you'll be doing totally OK without Ctrl+S – Anton Arhipov Feb 01 '13 at 22:26
2

This may not be exactly what you want but normally I leave auto-save on, and when I need to compile the current class I'm working on, I just do Ctrl + Shift + F9.

Roberto
  • 987
  • 1
  • 9
  • 21
  • Ctrl + F9 => [Make project] Ctrl + Shift + F9 => [Compile selected file, package or module] see https://resources.jetbrains.com/storage/products/intellij-idea/docs/IntelliJIDEA_ReferenceCard.pdf – kouretinho Mar 28 '17 at 12:41
2

My IntelliJ IDEA version is 2017.3.4, and I modified some values so that it compiles automatically.

Settings

Registry

Maciej Treder
  • 11,866
  • 5
  • 51
  • 74
Evan Knox Thomas
  • 592
  • 6
  • 12