
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:

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

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:

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

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:

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:

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“:

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.
The post Add External JAR File to IntelliJ Project first appeared on Baeldung.