IntelliJ IDEA run/debug just one file

Here's a Maven-centric solution.

The default Intellij behavior is to remake the entire project, and that can be really annoying. I find myself adding a quick test class to run often, and I always have to:

  1. Remove the Build Project setting from the auto generated run configuration. And this is after it tries to build everything.
  2. Shift-Meta F9 (or equivalent) to build just the class at hand
  3. Run the debug configuration.

enter image description here

This still won't build the module though. So, here is what I do now.

  • Remove the default build project setting from the default run configuration so you don't trigger it every time a new config is auto created.
  • Use Maven (or Gradle)
  • Set the run config to run the maven compile goal for the module

enter image description here

Now, everytime I debug, only the module compiles, and incrementally.


You can remove the Make task in your run configuration. But you have to compile the single class manually before launch (Right click or Build -> Compile your class).

Or you could even try to compile the whole project if you need more than a single class. This might work if you have no dependencies to a broken class.


I was looking for the same thing. Google let me to this topic first, so I'll post my solution here.

It is possible by replacing "Make" in the run configuration by a custom tool.

Remove "Make" and click the plus sign. Now select "Run external tool". Click the plus sign again to create a new custom tool.

Specify your command line Java compiler and set the output directory to the macro $OutputPath$.

Here is my configuration: Tool configuration

Now, specify this to be run before launch: External tool window

Works perfectly for my goal.


To run a single file in IntelliJ IDEA:

Way 1:

Right-click somewhere in the editing area and select Run 'ClassName.main()'. Say you want to run HelloWorld, you should do the steps below:

  1. Right-click somewhere in the editing area
  2. select Run 'HelloWorld.main()' from context menu enter image description here

Way 2:

  1. Open the file in editor
  2. Ctrl+Shift+F10