Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Introduction

IntelliJ IDEA is a widely used IDE for Java development, available in free and paid versions. In Java projects, JAR files contain reusable code and resources, making it easier to use external libraries.

We need to add JAR files to the classpath in IntelliJ IDEA to work with tools like Apache POI or JDBC drivers. This enables our project to recognize them during coding and execution.

In this tutorial, we’ll explore the steps to add an external JAR file to an IntelliJ IDEA project.

2. Why Add an External JAR File to IntelliJ IDEA?

Adding an external JAR file in our IntelliJ IDEA project enables us to use third-party libraries. These libraries provide extra features that Java doesn’t include by default. For example, Apache Commons Collections offers advanced data structures, Jackson helps with JSON processing, and MySQL Connector enables database connections.

By adding a JAR file, we can use these features in our project without writing the code manually. This is important for integrating external APIs, frameworks, and tools. IntelliJ IDEA makes sure our project recognizes these files so our code runs without errors.

3. Adding an External JAR File to the IntelliJ IDEA Project

To add an external JAR file to the IntelliJ project, first, we need to download it. To do this, we can visit a reliable source like Maven Repository or the library’s official website. Then, we can search for the required library and download the JAR file for our project.

After downloading a JAR file, we create a new IntelliJ IDEA project named baeldung:

create new intellij project

We navigate to the File section and then click on the Project Structure to open it:

open project structure

In the left panel, we go to Modules, select our module, click the Dependencies tab, and then press the + button to select an external JAR file:

select jars or directories

We choose JARs or Directories from the available options, locate the downloaded JAR file, and select it to add it to our project:

select the desired jar file

Finally, we click the OK button to add the commons-collections4-4.5.0-M3.jar file, in this case, to our IntelliJ IDEA project:

add the selected jar file

To verify the external JAR file inclusion, we can expand the External Libraries section in the Project view. If the JAR file appears there, it has been successfully added:

verify jar file

Once a JAR file is successfully added to our IntelliJ IDEA project, we can use any classes and methods it provides in our code.

3.1. Using External JAR File to Create a Simple Java Program

Let’s create a simple Java program that uses an external JAR file commons-collections4 to demonstrate the functionality of MultiValuedMap for storing multiple values under a single key.

First, we import MultiValuedMap and ArrayListValuedHashMap from Apache Commons Collections to handle multiple values per key:

import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;

Also, let’s define a test to check how MultiValuedMap from Apache Commons Collections handles multiple values for a single key:

@Test
void givenMultiValuedMap_whenAddingEntries_thenCanRetrieveThem() {
    MultiValuedMap<Integer, String> authorMap = new ArrayListValuedHashMap<>();

    // Adding multiple names for a single author ID
    authorMap.put(101, "Anees Asghar");
    authorMap.put(101, "A.A.");
    authorMap.put(102, "John Smith");
    authorMap.put(102, "J.S.");

    // Verify values for author ID 101
    Collection<String> names101 = authorMap.get(101);
    assertEquals(2, names101.size());
    assertTrue(names101.contains("Anees Asghar"));
    assertTrue(names101.contains("A.A."));

    // Verify values for author ID 102
    Collection<String> names102 = authorMap.get(102);
    assertEquals(2, names102.size());
    assertTrue(names102.contains("John Smith"));
    assertTrue(names102.contains("J.S."));

     // Verify that an unknown author ID returns an empty collection
    assertTrue(authorMap.get(103).isEmpty());
}

First, we initialize an ArrayListValuedHashMap and add multiple names for two author IDs (101 and 102).

Then, we verify that each ID correctly maps to the expected number of names and contains specific values. Finally, we check that querying a non-existent ID (103) returns an empty collection to ensure that the map behaves as expected.

If the JAR isn’t properly added, IntelliJ throws an error like “Cannot resolve symbol commons“:

cannot resolve symbol error

However, if IntelliJ IDEA recognizes the commons-collections4 JAR, the program compiles and runs successfully.

4. Conclusion

In this article, we explored steps to add an external JAR file to an IntelliJ IDEA project.

We can add a JAR file to the project’s classpath through the Project Structure > Modules > Dependencies section. Then, we can expand the External Libraries section in the Project view to verify the JAR file inclusion in our IntelliJ project.

Adding an external JAR file to an IntelliJ IDEA project lets us use extra features from third-party libraries that Java doesn’t include by default. Moreover, it helps us add tools like database connectors, logging systems, or utility functions, which makes our project more powerful.

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW