Home > Java > javaTutorial > How to Package Dependencies into a Single JAR File with Maven?

How to Package Dependencies into a Single JAR File with Maven?

Barbara Streisand
Release: 2024-12-22 05:15:11
Original
1061 people have browsed it

How to Package Dependencies into a Single JAR File with Maven?

Packaging Dependencies within a JAR using Maven

Problem:

How to incorporate all dependencies into a solitary JAR file using Maven?

Background:

A project is designed to build into a single JAR file. However, there is a need to include class files from the dependencies within the JAR as well.

Solution:

Maven's maven-assembly-plugin provides a solution for this requirement. It contains a descriptor named "jar-with-dependencies" that enables the following:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
</plugin>
Copy after login

This configuration unpacks JARs specified as dependencies and integrates the class files into the main JAR. It alleviates the limitations of nesting JAR files and ensures that all necessary code is bundled within the single distributable JAR file.

The above is the detailed content of How to Package Dependencies into a Single JAR File with Maven?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template