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

soemirno

I want to package my project in a single executable JAR for distribution.

How can I make a Maven project package all dependency JARs into my output JAR?

IAdapter
<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

and you run it with

mvn clean compile assembly:single

Compile goal should be added before assembly:single or otherwise the code on your own project is not included.

See more details in comments.


Commonly this goal is tied to a build phase to execute automatically. This ensures the JAR is built when executing mvn install or performing a deployment/release.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>fully.qualified.MainClass</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I create an executable jar file including dependencies where the main class is in Test, using Maven

From Dev

executable jar with dependencies using maven

From Java

How do I create an executable fat jar with Gradle with implementation dependencies

From Dev

How do I create an executable fat jar with Gradle with implementation dependencies

From Dev

How to create a executable jar file using Maven and Netbeans

From Dev

Combine java code and dependencies into one jar (executable jar) using maven

From Dev

create a executable jar using maven and jetty

From Dev

How can I create single executable jar in my gradle project

From Dev

How to make an executable jar using maven?

From Dev

How do I create a jar with all dependencies using Gradle 4.4?

From Dev

How can I produce a Crystal executable with no dependencies?

From Dev

Create executable jar with maven where libraries can be replaced

From Dev

How to create executable jar using maven for Javafx Application with its dependent jars?

From Dev

How can I make a .jar file executable?

From Dev

Eclipse: How to build an executable jar using ant with external project dependencies?

From Dev

Maven and Netbeans: how do I build project and get executable jar?

From Dev

maven multimodule project: can I jar-with-dependencies?

From Dev

Maven: Can I package only dependencies(without app) in a jar?

From Dev

How to add classpath properties to executable jar using maven assembly

From Dev

How to create maven uber jar which includes dependencies with scope provided

From Dev

How to create a jar with Maven that includes dependencies in a separate folder for each dependency

From Dev

How can I create an executable in Linux (beginner)?

From Dev

How can I create an executable in Linux (beginner)?

From Dev

Using Maven in Ant for jar dependencies

From Dev

To create a single executable jar file Maven

From Dev

How to create executable JAR with Gradle?

From Dev

How to create empty jar using maven

From Dev

gradle executable jar can't include local jar dependencies

From Dev

How do you create then run an executable jar with dependencies in Intellij IDEs, specifically Android Studio?

Related Related

  1. 1

    How do I create an executable jar file including dependencies where the main class is in Test, using Maven

  2. 2

    executable jar with dependencies using maven

  3. 3

    How do I create an executable fat jar with Gradle with implementation dependencies

  4. 4

    How do I create an executable fat jar with Gradle with implementation dependencies

  5. 5

    How to create a executable jar file using Maven and Netbeans

  6. 6

    Combine java code and dependencies into one jar (executable jar) using maven

  7. 7

    create a executable jar using maven and jetty

  8. 8

    How can I create single executable jar in my gradle project

  9. 9

    How to make an executable jar using maven?

  10. 10

    How do I create a jar with all dependencies using Gradle 4.4?

  11. 11

    How can I produce a Crystal executable with no dependencies?

  12. 12

    Create executable jar with maven where libraries can be replaced

  13. 13

    How to create executable jar using maven for Javafx Application with its dependent jars?

  14. 14

    How can I make a .jar file executable?

  15. 15

    Eclipse: How to build an executable jar using ant with external project dependencies?

  16. 16

    Maven and Netbeans: how do I build project and get executable jar?

  17. 17

    maven multimodule project: can I jar-with-dependencies?

  18. 18

    Maven: Can I package only dependencies(without app) in a jar?

  19. 19

    How to add classpath properties to executable jar using maven assembly

  20. 20

    How to create maven uber jar which includes dependencies with scope provided

  21. 21

    How to create a jar with Maven that includes dependencies in a separate folder for each dependency

  22. 22

    How can I create an executable in Linux (beginner)?

  23. 23

    How can I create an executable in Linux (beginner)?

  24. 24

    Using Maven in Ant for jar dependencies

  25. 25

    To create a single executable jar file Maven

  26. 26

    How to create executable JAR with Gradle?

  27. 27

    How to create empty jar using maven

  28. 28

    gradle executable jar can't include local jar dependencies

  29. 29

    How do you create then run an executable jar with dependencies in Intellij IDEs, specifically Android Studio?

HotTag

Archive