Home > Java > javaTutorial > How Can I Use the Maven Assembly Plugin to Create a Single JAR with Dependencies?

How Can I Use the Maven Assembly Plugin to Create a Single JAR with Dependencies?

Linda Hamilton
Release: 2024-12-31 19:51:15
Original
160 people have browsed it

How Can I Use the Maven Assembly Plugin to Create a Single JAR with Dependencies?

Maven jar-with-dependencies Plugin for Consolidating Dependencies

Maven provides a powerful feature to combine all project dependencies into a single jar file, offering convenience and enhanced portability.

Unpacking Dependencies into a Single Jar

The maven-assembly plugin plays a crucial role in this process. By utilizing the "jar-with-dependencies" descriptor, you can unpack the classes from dependency jars and bundle them into your main jar.

Configuring the Assembly Plugin

To leverage this functionality, include the maven-assembly-plugin in your pom.xml with the necessary configuration:

  <build>
    <plugins>
      <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>
    </plugins>
  </build>
Copy after login

The "jar-with-dependencies" descriptor ensures that the resulting single jar contains all the necessary class files, making your application self-contained and easy to deploy.

The above is the detailed content of How Can I Use the Maven Assembly Plugin to Create a Single JAR with Dependencies?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template