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?
Steps for adding external jars in IntelliJ IDEA:
File
from the toolbarLibraries cannot be directly used in any program if not properly added to the project gradle files.
This can easily be done in smart IDEs like inteli J.
1) First as a convention add a folder names 'libs' under your project src file. (this can easily be done using the IDE itself)
2) then copy or add your library file (eg: .jar file) to the folder named 'libs'
3) now you can see the library file inside the libs folder. Now right click on the file and select 'add as library'. And this will fix all the relevant files in your program and library will be directly available for your use.
Please note:
Whenever you are adding libraries to a project, make sure that the project supports the library
You add them as libraries to your module.
I usually have a
/lib
directory in my source. I put all the JARs I need there, add /lib as a library, and make it part of my module dependencies.2018 update: I'm using IntelliJ 2017/2018 now.
I'm fully committed to Maven and Nexus for dependency management.
This is the way the world has gone. Every open source Java project that I know of uses Maven or Gradle. You should, too.
Just copy-paste the .jar under the libs folder, right click on it and select 'Add as library' option from the list. It will do the rest...
I use this method and it works well:
1- Copy And paste the
.jar
files under thelibs
folder.2- Add
compile fileTree(dir: 'libs', include: '*.jar')
todependencies
inbuild.gradle
then all the jars in thelibs
folder will be included..3- Right click on
libs
folder and select 'Add as library' option from the list.Some great help found here. However, I still could not make it to work despite loading JAR properly. I found out later that I accidentally created module in the file structure instead of regular folder and this very module was pre-selected in the project setting.
Here is the footprint: