How to Create an Executable JAR with Maven?

Last Updated : 18 Mar, 2026

Maven is a build automation tool used for Java projects that simplifies build, dependency management, and configuration using a central POM file. It also helps in creating executable JAR files, which bundle all class files, resources, and dependencies into a single package for easy distribution and execution.

  • POM file is the core of Maven that manages project configuration and dependencies
  • Executable JAR contains a main class and all required dependencies to run the application

Create an Executable JAR with Maven

For creating Executable JAR we have some ways below listed them.

  • Using the Maven Assembly Plugin.
  • Using the Maven Shade Plugin.
  • Using the Maven Jar Plugin.
  • Using maven Commands.

Tools and Technologies

  • Java Programming
  • Java Version 17
  • Maven 3.X.X
  • JUnit
  • Spring Tool Suite

Steps to Create an Executable JAR with Maven

Here we created a simple maven project by using spring initializr with required maven dependencies and we mention them in the below.

Step 1: Create a Maven project by using Spring Tool Suite with basic dependencies.

Java
<dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

</dependencies>


Step 2: Once project created successfully, Now observe the project folder structure. The maven tool can provide standard structure to understand the project structure easily.

project folder
project folder

Step 3: Now located the pom.xml file open It now observe the dependencies in that file. This file contains information like project configuration, dependency management and other project related information.

XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.app</groupId>
    <artifactId>mavenpro</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mavenpro</name>
    <description>Spring Reactive</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Step 4: Now change the pom.xml file for creating executable JAR with maven below we provide the required XML configuration.

Using the Maven Assembly Plugin:

Java
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.example.MainClass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Now update the Maven Project after this run this project as Spring Boot App. Now refresh the project folder there is JAR is created.

folder---Copy

Step 5: In this step we use another approach to create an Executable JAR with Maven. Update the below configuration code in the pom.xml and update the project run this project.

Using the Maven Shade Plugin:

Java
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.example.MainClass</mainClass>
                            </transformers>
                        </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>


folder---Copy


Step 6: In this approach we use jar plugin to create an Executable JAR with Maven and update the pom.xml with below provide configuration code and update the project after this run the project.

Using the Maven Jar Plugin:

Java
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.example.MainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
folder


Step 7: In this step we use maven command to Create an Executable JAR with Maven that is

mvn clean package

To Create an Executable JAR with Maven command we need redirect into project folder by using CD command then run the above mention command after this refresh the project folder then you can observe the jar files in the project folder.

Output
Output


Comment
Article Tags:

Explore