Including dependencies in a jar with Maven

0 votes

Way to force maven to include all the dependencies in a single jar file?

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

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

Jul 20, 2018 in Java by Akrati
• 3,150 points
1,640 views

1 answer to this question.

0 votes

You can do this using the maven-assembly-plugin with the "jar-with-dependencies" descriptor. Here's the relevant chunk from one of our pom.xml's that does 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>
answered Jul 20, 2018 by samarth295
• 2,190 points

Related Questions In Java

+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,380 points

edited Nov 6, 2018 by Omkar 11,500 views
+2 votes
10 answers

How to import a jar file in Eclipse?

To import jar file in your Eclipse ...READ MORE

answered May 15, 2018 in Java by sharth
• 3,350 points
79,262 views
0 votes
1 answer

How to run a JAR file in Java?

The command given below will help you ...READ MORE

answered Jun 1, 2018 in Java by parth295
• 4,640 points
1,358 views
0 votes
2 answers

How to left pad a string with zero in java?

String paddedString = org.apache.commons.lang.StringUtils.leftPad("129018", 10, "0") the second ...READ MORE

answered Aug 31, 2018 in Java by Sushmita
• 6,880 points
598 views
0 votes
1 answer

How can I create an executable JAR with dependencies using Maven?

<build> <plugins> <plugin> ...READ MORE

answered Apr 26, 2018 in Java by sophia
• 1,400 points
239 views
0 votes
2 answers

How can we add the local JAR files to the Maven Project in Java?

Firstly I would like to give credit ...READ MORE

answered Nov 5, 2018 in Java by Sushmita
• 6,880 points
397 views
+1 vote
1 answer

How to tell the Maven to use the latest version of dependency in Java?

If you always want to use the ...READ MORE

answered Jun 26, 2018 in Java by Sushmita
• 6,880 points
2,387 views
0 votes
1 answer

Add jars to maven 2 build class path without installing them?

wn voteA quick&dirty batch solution (based on Alex's answer): libs.bat @ECHO ...READ MORE

answered Aug 29, 2018 in Java by samarth295
• 2,190 points
44 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 27, 2018 in Java by samarth295
• 2,190 points
130 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

answered Sep 3, 2018 in Java by Daisy
• 8,050 points
903 views