Problem/bug with "Build project automatically" IntelliJ 2017.3
I'm new to IntelliJ so there may or may not be a simple solution to this. Only tested this on Ubuntu 16.04.
In Netbeans, there is a quick way to compile and run a Java file that is currently open in the editor and re-compile it when it's changed, by setting "Compile on save" and then clicking "Run file". I've managed to make this work similarly in IntelliJ by setting "Build project automatically" and then using the default application run config, but removing "Build" under "Before launch" (since this is done automatically anyway). Here's the problem: there is currently three possible outcomes when changing something to a Java file in the editor and then running it:
1. If I change something and then immediately run it, the old class file will be run, as shown in the output in the run tool window.
2. If I change something and then wait about 1 sec and then run it (on this computer at least) I get "Error: Could not find or load main class [...]"
3. If I change something and then wait about 3 sec and then run it, then new changes are saved, compiled and run as shown in the output.
It's not really a problem waiting 3 seconds, but I wish I could see when the file is re-compiled and ready to be run, because this is NOT shown in the bottom of the window or in the event log (with default settings).
请先登录再写评论。
Build before launch should be present to avoid such problems. If automatic build has already occurred, it will not do anything and start your app right away.
That solved it, thanks!
If I use automatic build, it tries to build as I'm typing which causes the caret to lose focus because it shows errors. If I don't use automatic build, then it still errors because I have my run configurations set to build project before launch, however it starts running before the build is even complete and classes are written, so I get "could not load class ..."
Please try https://www.jetbrains.com/idea/nextversion/.
Unfortunately the issue is still in the EAP version
2018.2 version doesn't build as you type, it needs explicit Save.
Oh, I misunderstood, I thought you were referring to the issue with build before launch, but this still solves the problem. Thanks!
For the class not found with build before run issue please file a bug at https://youtrack.jetbrains.com/issues/IDEA and attach a sample project to reproduce.