
JAR files are an excellent way to distribute and deploy cross-platform applications written in Java. When the main-class is not specified in the manifest file, you must use the classpath flag ( -cp), not the -jar flag.

Notice the flag to run the JAR file has changed from -jar to -cp. If you know the Java class that should act as the entry point of a runnable JAR, you can explicitly specify that file at the command line as follows: java -cp jarfilename.jar

The Java JAR file uses a standard compression algorithm used by all of the most popular tools. The JAR file encompasses every file required to support an application, zipped up and compressed into a single, archive file. The term ‘archive’ is really key to understanding what a JAR file is. The term JAR is an acronym built from the words: Java Application a Rchive. JAR files are simply ZIP files that contain all of the resources required to run a Java application.

Commands to create, extract and run JAR files Function If the JAR file to run is located in a different folder, you’ll need to provide a full path to the file. This Java JAR run command assumes the JAR in question is located in the current folder. How do you run a JAR at the command line?Īs long as you have Java installed, and the PATH variable points to the \bin directory of the JDK, you issue the following command to run a JAR file at the command line: java -jar jarfilename.jar
