Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Last Updated: Mar 27, 2024
Difficulty: Medium

Maven Shade Plugin

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM


Maven is a build automation tool mainly used for Java projects. It is managed by Apache Software Foundation and can execute projects in different languages, including C#, Scala, Ruby etc. To support maven, we have several plugins available. These plugins are used to create jar files, war files, unit testing, code compilation etc. Each plugin generally provides a set of goals and is defined in the 'pom.xml' file.

Maven Shade Plugin

In this blog, we will discuss one such plugin called the maven shade plugin. We will go through a sample project examining the working and capabilities of this plugin.

Maven Shade Plugin

The maven shade plugin is a versatile plugin that is used for packaging the artifacts in uber-jar, including all of its dependencies. It also provides the feature to rename the packages of some of its dependencies. We can create a single independent jar file containing everything necessary to run the project. Other plugins, such as the assembly plugin, are also available, but the maven shade plugin is more advanced than the maven assembly plugin. The maven shade plugin has one defined goal:

✨ shade: It is invoked during the package phase.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Sample Project

Let's discuss a sample project where we will learn how to build a jar file using the shade plugin. 

Step 1: Install Eclipse IDE from the official website.

Step 2: Create a new maven project and select the simple project.

New Maven Project


Step 3: Specify the Group ID and Artifact ID as shown in the image below.


Step 4: Click on 'finish' to create the project. You will see the project structure similar to the image below. It will have J2SE 1.5 in the JRE System Libraries.

Project Structure


Step 5: Open the pom.xml file. It should look something like this.

pom file


Step 6: Insert the plugin tag and maven compiler plugin as shown in the image. Update the project by pressing Alt+F5 to see the changes.

Inserting plugin tag

Step 7: Add a new class file in the src/main/java/com/ninja directory. Name the class as ‘’. This file will contain the main method.

java class


Step 8: Our dependency directory is empty. Let's add a few dependencies in the pom.xml file. To add the dependency, search it in the central maven repository after searching for the dependency. We will use guava and JUnit in our sample project.

Central Repository


Step 9: Add some content in the main method to verify our dependency. We are using the isNullOrEmpty method from the guava dependency to check this fact. Run the project to see the output in the console.

Main demo java


Step 10: Our application is now ready. It's stored in the target directory. See the image below for more clarification.

target folder

Step 11: It's time to add the maven shade plugin. You can search for it from the central maven repository. Add all the content in the pom.xml file. Make sure to edit the package name according to your package.

Adding maven shade plugin

Step 12: Right-click on the project, run it as maven build, and set the goals to build the jar files using the shade plugin.

Setting up goals


Step 13: After clicking on the run button, the build process will show the logs in the console.


Step 14: Now, the build process is done. From the target directory, open a terminal and run the following command to execute the main file.

java -jar ninja-shade-plugin-demo-0.0.1-SNAPSHOT.jar

Final pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
                                <transformer />
                                <transformer implementation=" org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

Final file:

//demo java file


public class MainDemo {
    public static void main(String[] args) {
        String Name = "Manish";
        if (!Strings.isNullOrEmpty(Name)) {
            System.out.println("The string is correct:" + Name);


Must Read Apache Server

Frequently Asked Questions

What is Maven?

Maven is a build automation tool created by Apache Software Foundation. It can handle C#, Scala, Ruby etc. languages.

What is an uber jar file?

It is one level up from a simple jar file. It contains all of our packages and dependencies in a single jar file. It is independent and can be executed without any other needs.

What is a package?

A package is a complete set of files needed in a project. It contains all the dependencies and source code and can be shipped as the final product.


This blog has shed light on Maven Shade Plugin. It is a handy automation tool that is very needed for web and java developers. We also went through a sample project explaining how to build a jar file using the shade plugin.

More blogs on Maven:

You can find more Maven blogs on our platform: Coding Ninjas Studio.

To excel in the technical field, visit our platform Coding Ninjas Studio to learn more about JavaScript, DSA, Competitive Programming, System Design, etc. Enroll in our courses and refer to the mock test and problems available. To prepare for placements, follow our interview experiences and interview bundle curated especially for cracking technical jobs.

Happy Coding!

Topics covered
Maven Shade Plugin
Sample Project
Frequently Asked Questions
What is Maven?
What is an uber jar file?
What is a package?