IntelliJ run single Java file

Another option could be useful and quick for you. Just write your class with main method you want to run, and then press a little green triangle either behind your main method or behind your class name:

enter image description here

After that you will be able to choose an option e.g., Run, Debug or Run with Coverage:

enter image description here

In this case IDEA will just run your class without building the entire project.


You can change the Default settings based on your needs, to either automatically build after each change or manually. This can be achieved by clicking on File -> Other Settings -> Default Settings. This is the popup window.

Default Preferences

To change the run configurations, you can follow below steps.

  1. Goto Run tab at the top Toobar and click on Edit Configurations.
  2. Click + icon and select Application. This opens a new popup window where you can add all your VM arguments & Program arguments similar to Eclipse.