How to create the JAR file

The JAR file format is a compressed format used primarily to distribute Java applications and libraries. It is built on the ZIP file format, and functions in a similar way; many files are compressed and packaged together in a single file, making it easy to distribute the files over a network. If you need to package a Java application or library, you can create a JAR file using the Java Development Kit (JDK) and your computer’s command prompt.

Step 1:

Put all the files you want to include in the JAR file inside a single folder.

Step 2:

Open a Terminal command prompt, and set it to the target directory where your JAR files are located.

Step 3:

Run the following command in the terminal to make jar file,

[code]jar cfv HelloWorld.jar HelloWorld.class[/code]

The basic commands for creating the JAR file.

[code]jar cf jar-file.jar input-file(s)[/code]

The options and arguments used in this command are:

The “jar” portion refers to the jar.exe program, which compiles the JAR file.
The “c” option specifies that you want to create a JAR file
The “f” option means that you want to specify the filename.
The “jar-file” portion is where you should type the name that you want the file to have.
“Input-file(s)” is a space-separated list of all the files to be included in the JAR file.

Permanent link to this article: https://blog.openshell.in/2014/08/how-to-create-the-jar-file/