IntelliJ IDEA 2022.1 Help

Artifacts

An artifact is an assembly of your project assets that you put together to test, deploy, or distribute your software solution or its part. Examples are a collection of compiled Java classes or a Java application packaged in a Java archive, a Web application as a directory structure or a Web application archive, and so on.

An artifact can be an archive file or a directory structure that includes the following structural elements:

  • Compilation output for one or more of your modules

  • Libraries included in module dependencies

  • Collections of resources (web pages, images, descriptor files, and so on)

  • Other artifacts

  • Individual files, directories and archives

Artifact configurations

Artifacts are generated according to artifact configurations. You can manage artifact configurations in the Project Structure dialog.

Create an artifact configuration

  1. From the main menu, select File | Project Structure (Ctrl+Alt+Shift+S) and click Artifacts.

  2. Click Add and select an artifact format.

  3. On the page that opens in the right-hand part of the dialog, specify the artifact settings and contents.

Create an artifact configuration for the JAR

  1. From the main menu, select File | Project Structure (Ctrl+Alt+Shift+S) and click Artifacts.

  2. Click the Add button, point to JAR and select From modules with dependencies.

  3. To the right of the Main Class field, click the Browse button and select HelloWorld (com.example.helloworld) in the dialog that opens.

    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.

Build artifacts

You can build an artifact manually or you can automate this action by configuring it in the corresponding run/debug configuration.

By default, artifacts are placed to the out/artifacts/<artifact_dir> folder.

Build an artifact manually

  1. From the main menu, select Build | Build Artifacts.

  2. Point to the necessary artifact and select Build.

    In this popup, the following options are also available:

    • Build: build the whole artifact. After that the artifact will be built incrementally: the IDE will build only the changes that were made since the last build.

    • Rebuild: build the whole artifact as if for the first time. Technically, this is Clean followed by Build.

    • Clean: delete all the contents of the artifact output directory.

    • Edit: edit the artifact configuration.

    Building an artifact

Build an artifact while executing a run configuration

Including the Build artifact task in a run/debug configuration makes sense when the run configuration somehow uses the corresponding artifact. For example, if it starts the application packaged in a JAR artifact or deploys a WAR or EAR artifact to an application server.

  1. Press Ctrl+Shift+A, find and run the Edit Configurations action.

  2. In the Run/Debug Configurations dialog, select the necessary configuration or click the Add button to create a new one.

  3. Scroll down the dialog and under Before launch, click the Add button, select Build Artifacts. Select the necessary artifact.

    The selected artifact will be built automatically every time you execute this run configuration.

Run JAR artifacts

To run Java applications packaged in Java archives (JARs), IntelliJ IDEA provides the JAR Application run configurations. To create such a run configuration:

Create a run configuration

  1. Press Ctrl+Shift+A, find and run the Edit Configurations action.

  2. In the Run/Debug Configurations dialog, click the Add button and select JAR Application.

  3. Name the new configuration.

    Creating a new run configuration

Execute the run configuration

  • On the toolbar, select the configuration you want to run and click the Run button to the right of the run configuration selector. Alternatively, press Shift+F10.

    The Run tool window opens and shows you the application output.

Running the packaged application

The process has exited successfully, which means that the application is packaged correctly.

Deploy artifacts to application servers and cloud platforms

Many of the artifact formats (for example, WAR, Exploded WAR, EAR, Exploded EAR) are suitable for deployment to application servers and cloud platforms. Here is how you deploy such artifacts:

  1. In a server or cloud run/debug configuration, specify the artifact to be deployed. (Use the Deployment tab or field.)

  2. Execute the run/debug configuration or use the Deploy option Deploy in the Application Servers, Run or Debug tool window.

For more information, refer to Deploy artifacts to the cloud or Application server run configurations.

Examples

Examples of the procedures discussed on this page can be found in the following tutorials:

Last modified: 10 August 2022