# Compile and build applications with IntelliJ IDEA

The IntelliJ IDEA compilation and building process compiles source files and brings together external libraries, properties files, and configurations to produce a living application. IntelliJ IDEA uses a compiler that works according to the Java specification.

You can compile a single file, use the incremental build for a module or a project, and rebuild a project from scratch.

If you have a pure Java or a Kotlin project we recommend that you use IntelliJ IDEA to build your project since IntelliJ IDEA supports the incremental build which significantly speeds up the building process.

However, IntelliJ IDEA native builder might not correctly build the Gradle or Maven project if its build script file uses custom plugins or tasks. In this case, the build delegation to [Gradle](work-with-gradle-projects.html#delegate_build_actions) or [Maven](delegate-build-and-run-actions-to-maven.html#delegate_to_maven) can help you build your project correctly.

Procedure: Compile a single file or class

* Open the needed file in the editor and go to `Build | Recompile 'class name'` (`Ctrl+Shift+F9` (Windows), `⌘ ⇧ F9` (macOS), `⌘ ⇧ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F9` (macOS System Shortcuts), `Ctrl+Shift+F9` (XWin), `Ctrl+Shift+F9` (GNOME), `Ctrl+Shift+F9` (KDE), `Ctrl+Shift+F9` (Emacs), `Ctrl+B` (Sublime Text), `⌘ B` (Sublime Text (macOS)), `F9` (NetBeans), `Ctrl+F7` (Visual Studio), `⌘ F7` (Visual Studio (macOS)), `Ctrl+Shift+F9` (Eclipse), `⌘ ⇧ F9` (Eclipse (macOS))) in the main menu.

Alternatively, in the Project tool window, right-click the class you need and from the context menu, select Recompile 'class name'.

If errors occur during the compilation process, IntelliJ IDEA will display them in the [Review compilation and build output](#see-results) along with warning messages.

## Change the compilation output locations

When you compile your source code, IntelliJ IDEA automatically creates an output directory that contains compiled `.class` files.

![Compile output directory](https://resources.jetbrains.com/help/img/idea/2026.2/compiler_output.png)

Inside the output directory, IntelliJ IDEA also creates subdirectories for each of your modules.

The default paths for subdirectories are as follows:

* Sources: `<ProjectFolder>/out/production/<ModuleName>`

* Tests: `<ProjectFolder>/out/test/<ModuleName>`

At the project level, you can change the `<ProjectFolder>/out` part of the output path. If you do so (say, specify some `<OutputFolder>` instead of `<ProjectFolder>/out`) but don't redefine the paths at the module level, the compilation results will go to `<OutputFolder>/production/<ModuleName>` and `<OutputFolder>/test/<ModuleName>`.

At the module level, you can specify any desirable compilation output location for the module sources and tests individually.

Procedure: Specify compilation output folders

1. Open the Project Structure dialog (File | Project Structure `Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS))).

2. In Project Settings, select Project and in the Project compiler output field, specify the corresponding path.

![Project Structure dialog / Projects page](https://resources.jetbrains.com/help/img/idea/2026.2/project_compiler_output.png)

For modules, select Modules, the module you need and the Paths tab. Change the location of the output folder under the Compiler output section.

![Project Structure dialog / Module page](https://resources.jetbrains.com/help/img/idea/2026.2/module_compiler_output.png)

## Build

When you execute the Build ![the Build Project icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.toolwindows.toolWindowBuild.svg) command, IntelliJ IDEA compiles all the classes inside your build target and places them inside the output directory.

When you change any class inside the build target and then execute the build action, IntelliJ IDEA performs the incremental build that compiles only the changed classes. IntelliJ IDEA also recursively builds the classes' dependencies.

Procedure: Build a module, or a project

* Select a module or a project you want to compile and go to `Build | Build Project` (`Ctrl+F9` (Windows), `⌘ F9` (macOS), `⌘ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ B` (macOS System Shortcuts), `Ctrl+F9` (XWin), `Ctrl+F9` (GNOME), `Ctrl+9` (KDE), `Ctrl+F9` (Emacs), `Ctrl+F9` (Sublime Text), `Ctrl+F9` (Sublime Text (macOS)), `F11` (NetBeans), `F7` (Visual Studio), `F7` (Visual Studio (macOS)), `Ctrl+F9` (Eclipse), `⌘ B` (Eclipse (macOS))).

IntelliJ IDEA displays the compilation results in the [Review compilation and build output](#see-results).

If you add a module dependency to your primary module and build the module, IntelliJ IDEA builds the dependent module as well and displays it in the output directory alongside the primary one. If the dependent module has its own module dependencies, then IntelliJ IDEA compiles all of them recursively starting with the least dependent module.

![Project Structure dialog / Module page](https://resources.jetbrains.com/help/img/idea/2026.2/recursive_build.png)

The way the module dependencies are ordered may be very important for the compilation to succeed. If any two JAR files contain classes with the same name, the IntelliJ IDEA compiler will use the classes from the first JAR file it locates in the classpath.

For more information, refer to [Module dependencies](working-with-module-dependencies.html).

## Rebuild

When you execute a rebuild command, IntelliJ IDEA cleans out the entire output directory, deletes the build caches and builds a project, or a module from scratch.  It might be helpful when the classpath entries have changed. For example, SDKs or libraries that the project uses are added, removed or altered.

Procedure: Rebuild a module, or a project

* In the main menu, go to `Build | Rebuild Project` for the entire project or `Build | Rebuild 'module name'` for the module rebuild.

IntelliJ IDEA displays the build results in the [Review compilation and build output](#see-results).

> **Note:**
> When the  Rebuild Project action is delegated to [Gradle](work-with-gradle-projects.html#delegate_build_gradle) or [Maven](delegate-build-and-run-actions-to-maven.html#delegate_to_maven), IntelliJ IDEA doesn't include the `clean` task/goal when rebuilding a project. If you need, you can execute the `clean` command before the rebuild using the Execute Before Rebuild option in the [Gradle](jetgradle-tool-window.html) or [Maven](maven-projects-tool-window.html) tool window.

## Background compilation (auto-build)

You can configure IntelliJ IDEA to build your project automatically, every time you make changes to it. The results of the background compilation are displayed in the [Problems tool window](#see-results).

Procedure: Configure the background compilation

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Build, Execution, Deployment | Compiler`.

2. On the Compiler page, select  Build project automatically .

Now when you make changes in the class files, IntelliJ IDEA automatically performs the incremental build of the project.

The automatic build also gets triggered when you save the file (`Ctrl+S` (Windows), `⌘ S` (macOS), `⌘ S` (IntelliJ IDEA Classic (macOS)), `⌘ S` (macOS System Shortcuts), `Ctrl+S` (XWin), `Ctrl+S` (GNOME), `Ctrl+S` (KDE), `Ctrl+X, Ctrl+S` (Emacs), `Ctrl+S` (Sublime Text), `⌘ S` (Sublime Text (macOS)), `Ctrl+S` (NetBeans), `Ctrl+Shift+S` (Visual Studio), `⌘ ⇧ S` (Visual Studio (macOS)), `Ctrl+S` (Eclipse), `⌘ S` (Eclipse (macOS))) or when you have the Save files automatically if application is idle for N sec. option selected in the [System settings](system-settings.html#sync) dialog.

> **Tip:**
> Enabling the Build project automatically option also enables [Build project](saving-and-reverting-changes.html#actions-on-save) in `Settings | Tools | Actions on Save`

> **Note:**
> When you have the Power Save Mode option (`File | Power Save Mode`) enabled in your project, the auto-build action is disabled, and you need to manually run the build (`Ctrl+F9` (Windows), `⌘ F9` (macOS), `⌘ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ B` (macOS System Shortcuts), `Ctrl+F9` (XWin), `Ctrl+F9` (GNOME), `Ctrl+9` (KDE), `Ctrl+F9` (Emacs), `Ctrl+F9` (Sublime Text), `Ctrl+F9` (Sublime Text (macOS)), `F11` (NetBeans), `F7` (Visual Studio), `F7` (Visual Studio (macOS)), `Ctrl+F9` (Eclipse), `⌘ B` (Eclipse (macOS))).

## Compile before running

By default, when you run an application, IntelliJ IDEA [compiles](#compile_module) the module in which the classes you are trying to run are located.

If you want to change that behavior, you can do so in the [Run/Debug Configurations](run-debug-configurations-dialog.html) dialog.

Procedure: Configure a run/debug configuration

1. In the main menu, go to `Run | Edit Configurations`.

2. In the dialog that opens, create a new or open an existing run configuration.

3. Click the Modify options link.

4. In the Add Run Options list, under the Before Launch section, select Add before launch task. The list of tasks becomes available and the Build will be selected. Click ![the Close icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.closeSmall.svg) to disable it.

![Run/Debug Configuration dialog: Before launch](https://resources.jetbrains.com/help/img/idea/2026.2/run_config_before_launch.png)

5. If you need to add a new configuration action, click ![the Add button](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.add.svg) and from the list that opens, select the desired option.

For example, if you select Build Project then IntelliJ IDEA will build the whole project before the run. In this case, the dependencies that were not included in the build with the Build action, will be accounted for. If you select the Build, no error check option, IntelliJ IDEA will run the application even if there are errors in the compilation results.

![Run/Debug Configuration: Add new configuration.](https://resources.jetbrains.com/help/img/idea/2026.2/add_configuration.png)

## Review compilation and build output

IntelliJ IDEA reports compilation and building results in the [Build tool window](build-sync-tool-window.html), which displays messages about errors and warnings as well as successful steps of compilation.

![IntelliJ IDEA build output](https://resources.jetbrains.com/help/img/idea/2026.2/buildOutputJava.png)

If you configured an [auto-build](#auto-build), then IntelliJ IDEA uses the Problems tool window for messages. The window is available even if the build was executed successfully. To open it, click Auto-build on the status bar.

![Problems tool window](https://resources.jetbrains.com/help/img/idea/2026.2/problems_tool_window.png)

Double-click a message to jump to the problem in the source code. If you need to adjust the [compiler settings](compiler.html), click ![the Compiler Properties icon](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.settings.svg).

## Package an application into a JAR

When the code is compiled and ready, you can package your application in a Java archive (JAR) to share it with other developers. A built Java archive is called an artifact.

Procedure: Create an artifact configuration for the JAR

1. In the main menu, go to File | Project Structure `Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS)) and click Artifacts.

2. Click ![the Add button](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.add.svg), point to JAR, and select From modules with dependencies.

3. To the right of the Main Class field, click ![the Browse button](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.open.svg) and select the main class in the dialog that opens (for example, HelloWorld (com.example.helloworld)).

IntelliJ IDEA creates the artifact configuration and shows its settings in the right-hand part of the Project Structure dialog.

4. Apply the changes and close the dialog.

![Creating an artifact configuration](https://resources.jetbrains.com/help/img/idea/2026.2/manifest.animated.gif)

Procedure: Build the JAR artifact

1. In the main menu, go to Build | Build Artifacts.

2. Point to the created `.jar` (HelloWorld:jar) and select Build.

If you now look at the `out/artifacts` folder, you'll find your `.jar` file there.

![The JAR artifact is built](https://resources.jetbrains.com/help/img/idea/2026.2/jt-jar-built.png)

When you're building a project, resources stored in the [Resources root](content-roots.html#folder-categories) are copied into the compilation output folder by default. If necessary, you can [specify another directory](content-roots.html#specify_output_path) within the output folder to place resources.

## Add other files to a JAR artifact

You can add other files to a JAR artifact. For example, you can add some image files, configuration files, and JAR files.

Procedure: Add a file to a JAR artifact

1. In the main menu, go to File | Project Structure `Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS)) and click Artifacts.

2. Under Output Layout, click ![the Add Copy of](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.add.svg).

3. From the context menu, select File.

4. In the dialog that opens, locate the file, add it and click OK.

5. In the main menu, go to Build | Build Artifacts.

6. Point to the created `.jar` and select Build.

The built JAR artifact includes the added files.

## Run a packaged JAR

To run a Java application packaged in a JAR, IntelliJ IDEA allows you to create a dedicated run configuration.

> **Note:**
> If you have a [Gradle](getting-started-with-gradle.html) project, use Gradle to create and run the JAR file.
>
>
>
> For Maven projects, you can use IntelliJ IDEA to run a JAR file. If you have a Spring Boot Maven project, refer to the [Spring](your-first-spring-application.html) section.

Procedure: Create a run configuration

1. Press `Ctrl+Shift+A` (Windows), `⌘ ⇧ A` (macOS), `⌘ ⇧ A` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ P` (macOS System Shortcuts), `Ctrl+Shift+A` (XWin), `Ctrl+Shift+A` (GNOME), `Ctrl+Shift+A` (KDE), `Escape, X` (Emacs), `Ctrl+Shift+P` (Sublime Text), `⌘ ⇧ P` (Sublime Text (macOS)), `Ctrl+I` (NetBeans), `Ctrl+Shift+A` (Visual Studio), `⌘ ⇧ A` (Visual Studio (macOS)), `Ctrl+Shift+A` (Eclipse), `⌘ 3` (Eclipse (macOS)), find and run the Edit Configurations action.

2. In the Run/Debug Configurations dialog, click ![the Add button](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.add.svg) and select JAR Application.

3. Add a name for the new configuration.

![Creating a new run configuration](https://resources.jetbrains.com/help/img/idea/2026.2/run-debug.animated.gif)

4. In the Path to JAR field, click ![the Browse button](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.open.svg) and specify the path to the JAR file on your computer.

5. Under Before launch, click ![the Add button](https://resources.jetbrains.com/help/img/idea/2026.2/app.expui.general.add.svg), select `Build Artifacts` in the dialog that opens.

Doing this means that the JAR is built automatically every time you execute the run configuration.

[Video](https://resources.jetbrains.com/help/img/idea/2026.2/run-config-ending.mp4)

Run configurations allow you to define how you want to run your application, with which arguments and options. You can have multiple run configurations for the same application, each with its own settings.

Procedure: Execute the run configuration

* On the toolbar, select the created configuration and click ![the Run button](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.execute.svg) to the right of the run configuration selector. Alternatively, press `Shift+F10` (Windows), `⌃ R` (macOS), `⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌥ ⇧ R` (macOS System Shortcuts), `Shift+F10` (XWin), `Shift+F10` (GNOME), `Shift+F10` (KDE), `Shift+F10` (Emacs), `Shift+F10` (Sublime Text), `Shift+F10` (Sublime Text (macOS)), `F6` (NetBeans), `Ctrl+F5` (Visual Studio), `⌃ F5` (Visual Studio (macOS)), `Alt+Shift+X` (Eclipse), `⌘ ⇧ F11` (Eclipse (macOS)) if you prefer shortcuts.

As before, the Run tool window opens and shows you the application output.

![Running the packaged application](https://resources.jetbrains.com/help/img/idea/2026.2/jt-run-jar.animated.gif)

If the process has exited successfully, then the application is packaged correctly.

## See also

### Procedures

[Configure annotation processors](annotation-processors-support.html) [Gradle build](work-with-gradle-projects.html#delegate_build_actions) [Maven build](delegate-build-and-run-actions-to-maven.html#delegate_to_maven)

