Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When creating a new Java project in IntelliJ IDEA, the following directories and files are created:

./projectname.iml ./projectname.ipr ./projectname.iws ./src/ 

I want to configure IntelliJ IDEA to include my dependency JARs in ./lib/*.jar to the project. What is the correct way to achieve this in IntelliJ IDEA?

like image 331
knorv Avatar asked Jun 26 '09 22:06

knorv


People also ask

How do I create a jar file with an external library?

You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.


2 Answers

IntelliJ IDEA 15 & 2016

  1. File > Project Structure...

    File > Project Structure

    or press Ctrl + Alt + Shift + S

  2. Project Settings > Modules > Dependencies > "+" sign > JARs or directories...

    Modules > Dependencies > JAR or directories

  3. Select the jar file and click on OK, then click on another OK button to confirm

    enter image description here

    enter image description here

  4. You can view the jar file in the "External Libraries" folder

    enter image description here

like image 25
ROMANIA_engineer Avatar answered Sep 19 '22 06:09

ROMANIA_engineer


dialogue in Intellij 20.3

Steps for adding external jars in IntelliJ IDEA:

  1. Click File from the toolbar
  2. Select Project Structure option (CTRL + SHIFT + ALT + S on Windows/Linux, + ; on Mac OS X)
  3. Select Modules at the left panel
  4. Select Dependencies tab
  5. Select + icon
  6. Select 1 JARs or directories option
like image 98
Cambium Avatar answered Sep 18 '22 06:09

Cambium