Correct Way to Add External Jars (Lib/*.Jar) to an Intellij Idea Project

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

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

How to add external library in IntelliJ IDEA?

Easier procedure on latest versions:

  • Copy jar to libs directory in the app (you can create the directory it if not there)
  • Refresh project so libs show up in the structure (right click on project top level, refresh/synchronize)
  • Expand libs and right click on the jar
  • Select "Add as Library"

Done

How to add a Jar file to external library on IntelliJ IDEA

You are trying to add a *-sources.jar, which is a file that only contains the sources (this is useful if you are debugging, and want to see what the library is doing).

Instead you need to add the jar file with the compiled code. Given the library name you mention, that would usually be called play-java-ebean_2.10.jar (that is: without -sources).

IntelliJ add external jar as dependency from relative path

If the library is inside the project root, the path will be stored relatively using the placeholder.

In the library .xml file or in the project .iml file you'll see something like this:

<component name="libraryTable">
<library name="log4j-1.2.17">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/log4j-1.2.17.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

How do you add external libraries to intellij project during setup?

In the File>Project Structure (Ctrl+Alt+Shift+S) there is a tab named libraries -> Click on + -> Libraries

Also you can create a project in which the dependencies are managed by Gradle or Maven. Depending on the library you want to import, there use to be a section on the website of each library dedicated to guiding how to import in Maven or Gradle.

How to add external jar library file to Intellij Idea android project

if you are using Gradle I believe you also should modify build.gradle for your module.
In section dependencies add line like this:

compile fileTree(dir: 'libs', include: ['*.jar'])

like in this answer:
https://stackoverflow.com/a/13072692/1570833
Hope this helps!
Cheers



Related Topics



Leave a reply



Submit