What is Jar File in Java – How to Create Java Jar File?

1. Objective

In our last tutorial, we discuss Java Comments. In this Java tutorial, we are going to learn about What is Java Jar file with an example. Moreover, we will study how to create Jar file, view, extract, update, and run Jar file in Java Programming Language.

So, let’s start Jar File in Java.

Jar File in Java

What is Jar File in Java and How to Create it

2. Jar File in Java

A JAR (Java Archive) is a package bundle record arranged normally used to total numerous Java class documents and related metadata and assets (content, pictures, and so forth.) into one record to disperse application programming or libraries on the Java stage.

Do you know What is Java File Class – java.io.File Class in Java

In simple words, a JAR record is a document that contains compacted adaptation of .class records, sound records, picture documents or registries. We can envision a .shake document as a compressed file(.zip) that is made by utilizing WinZip programming. Indeed, even, WinZip programming can be utilized to use to extricate the substance of a .jolt. So you can utilize them for errands, for example, lossless information pressure, documenting, decompression, and chronicle unloading.

3. How to Create a .jar File in Java?

Here, we discuss how to create, view, extract, update, and run a Java file.

a. Create a JAR File in Java

We use jar cf command to create a jar file.
Syntax –

jar cf jarfilename inputfiles
//cf represents the creation of file.
C:\> jar cf pack.jar pack

Let’s Learn Types of Constructor in Java

b. Viewing a JAR File in Java

Command –

jar tf jarfilename
// tf represents the contents of file

Example –

C:/> jar tf pack.jar
// viewing contents of pack.jar

Output –
Read Difference Between Abstract Class and Interface in Java

c. Extracting a JAR File in Java

Command –

jar xf jarfilename
//xf represents extracting of files
C:\> jar xf pack.jar

d. Updating a JAR File

Command –

jar uf jar-file input-file(s)
// updating the file

Example –

C:\>jar uf pack.jar

e. Running a JAR File

Command –

C:\>java -jar pack.jar
// requires a main class manifest header
Java Quiz

4. Conclusion

Hence, in this tutorial, we learned about the Jar files available in Java Programming Language, how to create, view, extract, update, and run it with their commands. Furthermore, if you have any query feel free to ask in a comment section.

Related Topic- Encapsulation in Java 

For reference 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.