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 Java

How can I create an executable jar without dependencies using Maven?

From Dev

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

From Dev

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

From Java

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 Java

How can I create single executable jar in my gradle project

From Java

How to produce an executable jar file with all maven dependencies?

From Java

How to make an executable jar using maven?

From Java

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 Java

How to create an executable jar which is executable (Maven-Jfoenix-Hibernate-IntelliJ) __ Can someone makes the subject resolve/close please

From Dev

Create executable jar with maven where libraries can be replaced

From Dev

How to create executable jar in Kotlin using maven-assembly-plugin without a main class?

From Dev

How can I create a Python standalone executable using Hy modules?

From Dev

How can I make a .jar file executable?

From Dev

How can I create a runnable JAR file with Maven + JavaFX

From Java

how can I reference a local file and include it with my maven assembly when creating an executable jar?

From Dev

Can I create an executable Python zip archive with dependencies?

From Java

spring-boot Maven: How to create executable jar with main class?

From Java

How to create spring-based executable jar with maven?

From Dev

How to create executable jar file from springboot - maven application?

From Java

How can I run code locally with dependencies and exclude them when creating a Jar with Maven

From Dev

How can I put all dependencies into one folder inside a JAR file with Maven?

From Java

How can I visualize jar (not plugin) dependencies?

From Java

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

From Dev

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

From Dev

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

From Dev

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

Related Related

  1. 1

    How can I create an executable jar without dependencies using Maven?

  2. 2

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

  3. 3

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

  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

    How can I create single executable jar in my gradle project

  8. 8

    How to produce an executable jar file with all maven dependencies?

  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

    How to create an executable jar which is executable (Maven-Jfoenix-Hibernate-IntelliJ) __ Can someone makes the subject resolve/close please

  13. 13

    Create executable jar with maven where libraries can be replaced

  14. 14

    How to create executable jar in Kotlin using maven-assembly-plugin without a main class?

  15. 15

    How can I create a Python standalone executable using Hy modules?

  16. 16

    How can I make a .jar file executable?

  17. 17

    How can I create a runnable JAR file with Maven + JavaFX

  18. 18

    how can I reference a local file and include it with my maven assembly when creating an executable jar?

  19. 19

    Can I create an executable Python zip archive with dependencies?

  20. 20

    spring-boot Maven: How to create executable jar with main class?

  21. 21

    How to create spring-based executable jar with maven?

  22. 22

    How to create executable jar file from springboot - maven application?

  23. 23

    How can I run code locally with dependencies and exclude them when creating a Jar with Maven

  24. 24

    How can I put all dependencies into one folder inside a JAR file with Maven?

  25. 25

    How can I visualize jar (not plugin) dependencies?

  26. 26

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

  27. 27

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

  28. 28

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

  29. 29

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

HotTag

Archive