How to create a runnable JAR file with Maven?

By | November 1, 2020

In this post, We will learn How to create a runnable JAR file with Maven? 

Sometimes when We create a jar file, we want to execute it easily without using any IDE.

To create an executable jar File, we don’t need any additional dependencies. You just need to create a Maven project and have at minimum one class with the main(…) method.

In our example, we created a Java class named App.

We also need to make sure that our pom.xml contains the following elements:

Let’s try to understand the above concept using a Demo Project:


Now right-click on your project then go to Run As -> Maven build…

Provide Goals clean package and Click on Run

Once maven build completes then open the command prompt and move to the target directory after that type command java -jar First-Demo-Project-0.0.1-SNAPSHOT.jar and press Enter

That’s all about How to create a runnable JAR file with Maven?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *