Run Java Class file from jar using cmd

There are two types of JAR files available in Java:

  1. jar with the manifest file
  2. jar without a manifest file

1. jar with the manifest file

Runnable/Executable jar file which contains the manifest file.

To run a Runnable jar you can use:

java -jar fileName.jar 


java -jar -classpath abc.jar fileName.jar

2. jar without a manifest file

Simple jar file that does not contain a manifest file so you simply run your main class by giving its path:

 java -cp ./fileName.jar MainClass