Core JavaJava

IntelliJ IDEA Include External JAR Example

1. Introduction

IntelliJ IDEA is an integrated development environment (IDE) developed by JetBrains. Including external JAR is essential for various reasons as the project may access external libraries or may need external jars when developing offline. In this example, I will show three common ways to include external JAR in an IntelliJ project.

  • Include external JAR to a Maven project.
  • Include external JAR to a Gradle Project.
  • Include external JAR to a Java project.

2. Intellij Include External JAR in Maven Project

It’s best to include external JAR as dependencies in pom.xml for a Maven project. Here is an example to add lombok.jar to the pom.xml file.

pom.xml

1
2
3
4
5
6
7
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.36</version>
    <scope>provided</scope>
</dependency>

After pom.xml is updated, click View-> Maven Tool Window and then click the "Reload All Maven Projects” icon. You can verify the lombok.jar under the project’s “Dependencies” folder as Figure 1.

intellij include external jar
Figure 1. Maven Dependencies

3. Intellij Include External JAR in Gradle Project

For a Gradle project, it’s best to add external JARs under the dependencies section in the build.gradle file. Here is an example to add the lombok.jar

build.gradle

1
2
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.36'

Click the “Load Gradle Changes” icon or run the gradle build task. Verify the external JARs added under “External Libraries” in Figure 2.

intellij include external jar
Figure 2. Gradle External Libraries

4. Intellij Include External JAR in Java Project

For the project without Maven/Gradel, we can add external JAR via its “Project Structure” feature with the following steps:

  • Prepare the external JARs. For this example, I downloaded the lombok.jar from the Maven Repository website and stored it in my PC’s Downloads folder.
  • In IntelliJ IDE, click File->Project Structure ..., then it pops a new “Project Structure” window.
  • Click the “Modules” under “Project Settings” in the “Project Structure” window.
  • Click the “Dependencies” tab and then click the “+” and select the “1. JARs or Directories...” option in Figure 3.
  • Select the lombok.jar from the Download folder and click the “Apply” then “OK” buttons in Figure 4.
  • Verified the lombok.jar is included under the “External Libraries” in Figure 5.

Add JARs

intellij include external jar
Figure 3. Project Structure

Add Lombok.jar

intellij include external jar
Figure 4. Add Dependencies

Verify The External JAR is Added

intellij include external jar
Figure 5. External Jar is Added

5. Conclusion

In this step, I donmonstrated three ways to include external JAR to an IntelliJ project.

  • Include external JAR to a Maven project via pom.xml
  • Include external JAR to a Gradle Project via build.gradle
  • Include external JAR to a Java project via “Project Structure” setting.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Mary Zheng

Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button