Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file?

I have a project the builds into a single jar file. I want the classes from dependencies to be copied into the jar as well.

I know that I can't just include a jar file in a jar file. I'm searching for a way to unpack the jars that are specified as dependencies and package the class files into my jar.

1 Answer

0 votes
by (46k points)

You can do that by applying the maven-assembly plugin with the "jar-with-dependencies" descriptor. Here's the appropriate piece from one of our pom.xml's that performs this:

  <build>

    <plugins>

      <!-- any other 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>

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 28, 2021 in Java by dante07 (13.1k points)

Browse Categories

...