intellij build executable jar

IntelliJ: Build & Run Executable JAR

By Amanda White
AD

Want to package your IntelliJ IDEA project as a runnable JAR file? You're in the right place. Here, we'll guide you through the process, ensuring your executable JAR reaches its destination swiftly and efficiently.

Before we dive in, ensure you have a project open in IntelliJ IDEA and that you've configured the build artifacts for your project. If you haven't, head over to File > Project Structure > Artifacts, click the plus icon, select 'Jar', and configure your main class and dependencies.

Preparing Your Project for Packaging

The first step in creating an executable JAR is ensuring your project is ready for packaging. This includes configuring your build artifacts and ensuring all necessary classpath elements are accounted for.

AD
a man is smiling and pointing at the camera with his finger up in front of him
a man is smiling and pointing at the camera with his finger up in front of him
10 Best IntelliJ Themes and Color Schemes
10 Best IntelliJ Themes and Color Schemes
the useful tools for building products are displayed in this screenshote image with caption below
the useful tools for building products are displayed in this screenshote image with caption below

Head to File > Project Structure > Artifacts, verify that you've added a 'Jar' artifact, and that your main class (e.g., 'MyApp') is specified. Include any required dependencies, libraries, or resources in the build path.

Exploring Artifacts Configuration

In the 'Artifacts' window, you'll find various configurable options. For 'From modules with dependencies', select the checkbox if your project depends on other modules. For 'Only main classes', ensure only your project's main class is listed to prevent including unnecessary files in your JAR.

the open source stack is shown in this screenshote screen shot from an iphone
the open source stack is shown in this screenshote screen shot from an iphone
Amazing Facts For Students, Small Business Advice, Career Exploration, Calligraphy For Beginners, Vision Board Manifestation, Interesting Reads, Learn To Code, Educational Websites, Life Improvement
Amazing Facts For Students, Small Business Advice, Career Exploration, Calligraphy For Beginners, Vision Board Manifestation, Interesting Reads, Learn To Code, Educational Websites, Life Improvement
How to build a scalable AI agent/Как создать масштабируемый ИИ-агент
How to build a scalable AI agent/Как создать масштабируемый ИИ-агент

You can also configure whether to include project sources, resources, or other resources, and whether to explore archives. Tailor these settings to suit your project's needs.

Setting the Main Class

Ensure your main class is set correctly. This is the class with a public static void main(String[] args) method, which serves as the entry point of your application. IntelliJ IDEA uses this class to launch your application in testified mode.

AD

You can set the main class by clicking on the 'Main Class' field in the 'Jar' artifact settings. A drop-down will appear, listing all potential main classes in your project. Select the correct one.

IntelliJ IDEA 2020.2.1 Is Available - The JetBrains Blog
IntelliJ IDEA 2020.2.1 Is Available - The JetBrains Blog
Get Names of Classes Inside a JAR File | Baeldung
Get Names of Classes Inside a JAR File | Baeldung
Trabajando con Intellij IDEA 11 - Adictos al trabajo
Trabajando con Intellij IDEA 11 - Adictos al trabajo
a poster with the words inteluli idea and some type of information on it's side
a poster with the words inteluli idea and some type of information on it's side
IntelliJ GC Overhead Limit Exceeded: Ultimate Fix Guide for Developers
IntelliJ GC Overhead Limit Exceeded: Ultimate Fix Guide for Developers
the build an agent in 10 minutes info sheet with instructions and examples for each user
the build an agent in 10 minutes info sheet with instructions and examples for each user

Creating the Executable JAR

Now that your project is configured, let's create the executable JAR. IntelliJ IDEA simplifies this process with its two-step approach: building and packaging.

This approach allows you to build your project first, ensuring there are no compile or runtime errors, before packaging it into a JAR.

AD

Building the Project

Before creating the JAR, navigate to the 'Build' menu (or press Ctrl+F9/Cmd+F9) and click on Build Artifacts. IntelliJ IDEA will build your project and highlight any compile-time or runtime errors in the console.

Data Science Learning, Electronics Basics, System Architecture, Ui Inspiration, Promote Book, Cheat Sheets, Big Data, Data Science, Project Management
Data Science Learning, Electronics Basics, System Architecture, Ui Inspiration, Promote Book, Cheat Sheets, Big Data, Data Science, Project Management

Fix any issues before proceeding, as they will likely cause your JAR to fail when run. If there are no errors, you're ready to package your project into a JAR.

Packaging the JAR

Once your project has been successfully built, you can package it into a JAR. Select the 'Jar' artifact in the 'Artifacts' window, then click on the 'Package' icon at the top of the window (or press Ctrl+Shift+F9/Cmd+Shift+F9).

AD

In the dialog that appears, choose the output directory and, optionally, configure additional packaging settings. Click 'Package' when you're ready. IntelliJ IDEA will create your packaging file in the specified output directory.

Your executable JAR is now ready for distribution or deployment. Its simple, double-click-to-run functionality is perfect for sharing with colleagues, deploying to servers, or even distributing as a software product.

AD