W3docs

Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project

To add external JAR files to an IntelliJ IDEA project, you can follow these steps:

To add external JAR files to an IntelliJ IDEA project, you can follow these steps:

  1. Open the project in IntelliJ IDEA.
  2. Open the Project Structure dialog by selecting File > Project Structure from the main menu, or by pressing Ctrl+Shift+Alt+S.
  3. In the Project Structure dialog, select the Modules item on the left side.
  4. In the Modules section on the right side, select the module you want to add the JAR file to.
  5. In the Dependencies tab, click the + button and select JARs or directories.
  6. In the Choose File or Directory dialog, navigate to the directory that contains the JAR file you want to add, select the JAR file, and click OK.
  7. Click Apply or OK in the Project Structure dialog to save the changes.

This will add the JAR file to the dependencies of the selected module.

Note that if you are using a build tool such as Maven or Gradle to manage the dependencies of your project, you should add the JAR file as a dependency in the build file instead of adding it directly to the classpath. This will ensure that the JAR file is included in the classpath of the project when it is built and deployed.