---
title: "How can I create an executable/runnable JAR with dependencies using Maven?"  
description: "How can I create an executable/runnable JAR with dependencies using Maven?"  
author: "Utpal Vishwas"  
published: 2023-07-21  
updated: 2023-07-22  
canonical: https://www.mindstick.com/forum/159220/how-can-i-create-an-executable-runnable-jar-with-dependencies-using-maven  
category: "tools"  
tags: ["tools", "maven"]  
reading_time: 2 minutes  

---

# How can I create an executable/runnable JAR with dependencies using Maven?

How can I create an executable/[runnable](https://www.mindstick.com/forum/160962/what-is-the-difference-between-callable-and-runnable-in-java) [JAR](https://www.mindstick.com/forum/23238/conversion-to-dalvik-format-failed-with-error-1-on-external-jar) with dependencies using [Maven](https://www.mindstick.com/forum/23196/how-can-i-create-an-executable-jar-with-dependencies-using-maven)?

## Replies

### Reply by Aryan Kumar

To create an executable/runnable jar with dependencies using Maven, you can use the `maven-assembly-plugin`. The `maven-assembly-plugin` allows you to package your project and its dependencies into a single JAR file.

To use the `maven-assembly-plugin`, you need to add the following dependency to your pom.xml file:

```plaintext
<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>3.3.0</version>
</dependency>
```

You also need to add the following configuration to your pom.xml file:

```plaintext
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.example.MyApplication</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>
```

The `mainClass` element specifies the class that should be executed when the JAR file is run. In this case, the main class is `com.example.MyApplication`.

The `jar-with-dependencies` descriptor ref tells the `maven-assembly-plugin` to include all of the dependencies of your project in the JAR file.

Once you have added the `maven-assembly-plugin` configuration to your pom.xml file, you can build your project by running the following command:

" mvn assembly:single "

This will create a JAR file in the `target/` directory of your project. The JAR file will be named `project-name-jar-with-dependencies.jar`.

You can then run the JAR file by executing the following command:

" java -jar project-name-jar-with-dependencies.jar "

This will run the `com.example.MyApplication` class, which is the main class of your project.


---

Original Source: https://www.mindstick.com/forum/159220/how-can-i-create-an-executable-runnable-jar-with-dependencies-using-maven

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
