Home >Java >javaTutorial >How to Include External Libraries in IntelliJ IDEA Artifact JARs?

How to Include External Libraries in IntelliJ IDEA Artifact JARs?

Barbara Streisand
Barbara StreisandOriginal
2024-12-25 20:40:15748browse

How to Include External Libraries in IntelliJ IDEA Artifact JARs?

Including External Libraries in Artifact JARs with IntelliJ IDEA

When building artifact JARs in IntelliJ IDEA, it's crucial to include essential external libraries. However, sometimes developers encounter challenges in ensuring that the libraries remain accessible during runtime.

To resolve this issue, there are two primary approaches:

1. Extract Dependencies into Artifact JAR:

This method integrates the external dependency into the artifact JAR, creating a standalone executable that contains all required dependencies.

Steps:

  1. Add the external JAR to the project's "Libraries" folder.
  2. Right-click on the project module, select "Build Artifacts," and create a new Jar artifact.
  3. In the "Output Properties" section, enable the "Extract to the JAR" option.
  4. Build the artifact by selecting "Build | Build Artifacts."

2. Link Dependent JARs via Manifest.MF and Copy:

Alternatively, dependent JARs can be linked via the project's Manifest.MF file and copied alongside the main artifact JAR.

Steps:

  1. Add the required JARs to the project's "Libraries" folder.
  2. In the "Project Structure" dialog, edit the "Manifest" tab (Ctrl Alt Shift M).
  3. Add the following line to the "Class-Path" attribute:

    Class-Path: path/to/dependency.jar
  4. Build the project and copy the dependent JARs to the target directory alongside the main artifact JAR.

The above is the detailed content of How to Include External Libraries in IntelliJ IDEA Artifact JARs?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn