Last Updated: October 20, 2022

How to create a runnable JAR file

Pre-Requisite:

Create a maven project.

Steps:

1.Go to the pom file. as shown in Figure 1.

 

project-screen1.png
Figure 1. prjoect
2.Add the plugin to the pom file. as shown in Figure 2.

 

Unresolved include directive in modules/6.x.x/pages/frameworks/tutorials/create-runnable-jar-tutorial.adoc - include::inc/runnable-jar1.xml[]
pomfile-screen2.png
Figure 2. pom file
change <mainClass>com.path.to.YourMainClass</mainClass> with path to your Main Class.
3.Update maven project. as shown in Figure 3.

Right-click on the project → Maven → Update Project Or Alt + F5, then Click OK.

update-maven-screen3.png
Figure 3. update maven project
4.Run the project as maven build. as shown in Figure 4.

Right-click on the Run As → Maven build ,Click on the package, then OK.

run-build-screen4.png
Figure 4. create runnable jar file

Wait for the build to finish. as shown in Figure 5.

project-build-success-screen5.png
Figure 5. create runnable jar file
5.Navigate to target file in your project location. as shown in Figure 6.

 

target-file-screen6.png
Figure 6. navigate to project

You should see a jar file created as shown in Figure 6.

6.Run with command line. as shown in Figure 7.

open CMD or Terminal and type :

cd [Path]

java -jar [YourJarName].jar
Replace [Path] with your project path and [YourJarName.jar] with your jar file name.
run-jar-file-screen7.png
Figure 7. run with command

You have created a runnable jar file.

Runnable Jar using Standard Maven Plugin

Unresolved include directive in modules/6.x.x/pages/frameworks/tutorials/create-runnable-jar-tutorial.adoc - include::inc/runnable-jar2.pom[]