What is the difference between "Module Dependencies" and "Libraries" in IntelliJ IDEA when you want to add a .jar
library to your project? Also, What is the "Export" check box when you are adding your .jar
library to the "Module Dependencies" in IntelliJ IDEA?
In each of these ways, how are the classes and code inside the included .jar
library integrated into your final project (code) when creating the newly generated .jar
file?
Dependency is a much more broader term than plain libraries. It can mean data, software installed, whatever. Maybe they meant to say “may depend on libraries and other dependencies”. A library is not the only thing software can depend on: configuration files, device drivers, databases, etc.
A library is a collection of compiled code that you can add to your project. In IntelliJ IDEA, libraries can be defined at three levels: global (available for many projects), project (available for all modules within a project), and module (available for one module).
A Module can reference a library which can be a project library or a global library. Global libraries have to be defined only once. Project library in every project you need them. Packages are a java concept and are IDE independent.
dependencies is code that is dependent on other code (ie Class Foo implements Bar) libraries are a group of classes that perform a similar function and are groups together so that they can easily be pulled into any project.
Module dependencies are classes, archives, libraries and resources that your module files references. While a library is a set of class files stored in an archive or directory.
Export check means if checked then this library will be implicitly added to the other module that references this one.
To create a .jar file you need create an artifact. Artifact is a placeholder of the building output. There's predefined templates for creating .jar, .war, .ear archives. You can choose jar to build a jar artifact. By default it's defined empty and you need to define content of the artifact. You can drag-n-drop compiled output to it but don't do it with library archives. Because libraries in this case will be packaged inside the .jar file and you will be required to create a separate classloader to load them before your application start. Instead you change the artifact type to Other and drag .jar and dependent libraries into output root. This way library archives will be copied along with created .jar. You also need to create a MANIFEST.MF and specify Class-Path there for dependent libraries. All files will be stored in the directory you specify for building the artifact. You can build it using Build Artifact menu.
If your project contains multiple modules, "module dependency" defines dependencies between these modules, but libraries are compiled classes (usually jar files, optionaly containing theirs sources and javadocs) that are used by your module.
Each module can have its own libraries and artifacts (for example a result jar file), and can depend on other modules without circular dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With