moorara
moorara

Reputation: 4226

What is the difference between "Module Dependencies" and "Libraries" in IntelliJ IDEA?

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?

Upvotes: 38

Views: 24061

Answers (4)

OSGI Java
OSGI Java

Reputation: 645

"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)."

  • Global library is set via Project Structure\Platform Settings\Global Libraries
  • Project library is set via Project Structure\Project Settings\Libraries
  • Module library is set via Project Structure\Project Settings\Modules\Dependencies

Upvotes: 3

Roman C
Roman C

Reputation: 1

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.

Upvotes: 13

Amir Pashazadeh
Amir Pashazadeh

Reputation: 7322

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.

Upvotes: 10

CrazyCoder
CrazyCoder

Reputation: 402433

Module Dependencies tab can contain Libraries, Export means that a library from the module will be also available to another module that depends on this module.

Final jar with all the dependencies can be created using Artifacts.

Upvotes: 3

Related Questions