Home >Java >javaTutorial >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>
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!