S
S
swaro2020-10-04 20:49:40
Java
swaro, 2020-10-04 20:49:40

How to include dependencies in jar?

Hello! How can I make Maven include all dependencies in the final JAR? With "mvn package" I only get the JAR with my code. At the moment my pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>me.swaro32</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.27</version>
        </dependency>
    </dependencies>
</project>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alfss, 2020-10-04
@alfss

Google fatjar, shadowjar

M
mystifier, 2020-10-05
@mystifier

Something like this in pom.xml

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <finalName>${project.artifactId}</finalName>
          <archive>
            <manifest>
              <mainClass>somepackage.SomeClass</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question