Create a JAR file

In order to create a .jar file, we can use jar cf command in the following ways as discussed below:

Syntax:

jar cf jarfilename inputfiles

Here, cf represents to create the file. For example , assuming our package pack is available in C:\directory , to convert it into a jar file into the pack.jar , we can give the command as: 

C:\> jar cf pack.jar pack

JAR files in Java

A JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform. 
In simple words, a JAR file is a file that contains a compressed version of .class files, audio files, image files, or directories. We can imagine a .jar file as a zipped file(.zip) that is created by using WinZip software. Even, WinZip software can be used to extract the contents of a .jar . So you can use them for tasks such as lossless data compression, archiving, decompression, and archive unpacking. 

Let us see how to create a .jar file and related commands which help us to work with .jar files 

Similar Reads

1.1 Create a JAR file

In order to create a .jar file, we can use jar cf command in the following ways as discussed below:...

1. 2 View a JAR file

Now, the pack.jar file is created. In order to view a JAR file ‘.jar’ files, we can use the command as:...

1.3 Extracting a JAR file

In order to extract the files from a .jar file, we can use the commands below listed:...

1.4 Updating a JAR File

The Jar tool provides a ‘u’ option that you can use to update the contents of an existing JAR file by modifying its manifest or by adding files. The basic command for adding files has this format as shown below:...

1.5 Running a JAR file

In order to run an application packaged as a JAR file (requires the Main-class manifest header), the following command can be used as listed:...

Related Article

Working with JAR and Manifest files In Java...