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:
- Open the project in IntelliJ IDEA.
- Open the Project Structure dialog by selecting File > Project Structure from the main menu, or by pressing Ctrl+Shift+Alt+S.
- In the Project Structure dialog, select the Modules item on the left side.
- In the Modules section on the right side, select the module you want to add the JAR file to.
- In the Dependencies tab, click the + button and select JARs or directories.
- 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.
This will add the JAR file to the dependencies of the selected module.
Alternatively, you can add the JAR file to the classpath of the project by placing it in the lib
directory at the root of the project. Then, IntelliJ IDEA will automatically detect the JAR file and add it to the classpath of the project.
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.