What is Jar File in Java – How to Create Java Jar File?
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.
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.
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.
jar cf jarfilename inputfiles //cf represents the creation of file. C:\> jar cf pack.jar pack
b. Viewing a JAR File in Java
jar tf jarfilename // tf represents the contents of file
C:/> jar tf pack.jar // viewing contents of pack.jar
Read Difference Between Abstract Class and Interface in Java
c. Extracting a JAR File in Java
jar xf jarfilename //xf represents extracting of files C:\> jar xf pack.jar
d. Updating a JAR File
jar uf jar-file input-file(s) // updating the file
C:\>jar uf pack.jar
e. Running a JAR File
C:\>java -jar pack.jar // requires a main class manifest header
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