This article will tell you how to create a jar file using Java’s Jar command in command prompt. Basically jar file format is formed from ZIP file format. Jar files are mainly used for archiving, compression and decompression.
Note : Java should be installed in your system to execute Jar command and also correct java path should be set up before starting.
Using Jar command you can create,view,delete,update/modify,extract and execute the jar files.
1. Creating a Jar file
jar cf JAR_NAME INPUT_FILENAME(S) OR DIRECTORY_NAME
c – create JAR file
f – Output should go to file rather than stdout (terminal)
JAR_NAME – Name of the Jar file (can give any filename you want). Filename should be given .jar extension
INPUT_FILENAME(S) – One or more files to be included in the JAR file and each file will be separated by a space
DIRECTORY_NAME – If the “input files” are directory, then the contents of the directory (given in the DIRECTORY_NAME) are added to the jar recursively.
Note : c and f should be in any order but should not have any space in between them