How do I create a JAR with dependent libraries?

Using Maven, how to create a JAR with dependent libraries? I am using mvn package, it does not include dependent libraries.

+3


source to share


1 answer


Use the Maven Build Plugin and configure it to jar-with-depdencies

.

From the doc:



For example, imagine our project is generating a JAR. If we want to create a binary assembly that includes our project dependencies, we can use one of the prefab plugins, prefab descriptors, as follows:

<project>
 [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <!-- NOTE: We don't need a groupId specification because the group is
             org.apache.maven.plugins ...which is assumed by default.
         -->
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        [...]
</project>

      

+6


source







All Articles