JAR stands for Java Archive file. It is a platform-independent file format that allows bundling and packaging all files associated with java application, class files, audio, and image files as well. These files are needed when we run an applet program. It bundles JAR files use a Data compression algorithm. These jar files can be manipulated using zip programs like WINZIP or WINRAR.
It enables ease of distribution as all class files are packaged/bundled together and distributed to client applications. as one single jar file. These jar files can be signed by an author using digital certificate. These jar files can be authenticated using digital certificates and checking the author's signature. The JRE (Java Runtime Environment) loads the classes from the JAR file without un-jarring it.
Methods: There are 2 ways of creating a JAR file.
- Using IDE
- Using the command line
Let us do discuss both of them in depth.
Method 1 - Using IDE
1. The creation of a JAR file through an IDE like Netbeans or Eclipse is pretty straightforward. In File, we have an export option that helps us to export the java application as a JAR file. After this go to
File -> Export->Java-> JAR file
2. Now in a JAR file specification dialog, specify the resources/files to be included in the JAR file. The export destination is the location where the jar file is to be created.
3. Click on the Finish button
4. We then provide the location where we wish to have the jar file created.
5. It is pictorially depicted below in two snapshots which are as follows:

Method 2: Using the command line
Using the jar tool, we can create a jar file as below
cmd>> jar cvf jarfile inputfileDir1 inputfileDir2
Here,
- c - create a new jar file
- v - verbose mode which displays the messages while the jar file is created.
- f - bundles into a jar file specified by the parameter jarfile instead of standard output.
- inputfileDir1, inputfileDir2 - indicates the input files which are to be bundled together in the jar file.
Now we will be manifesting the file as this is a special file that is bundled in your JAR file. It has special metadata like main class name, version control, the digital signature of the author, the java version used for bundling the jar file. The file name is "MANIFEST.MF" and it is a part of the META-INF subdirectory. If this file is not provided during bundling of the JAR file, it gets created automatically. When we extract and open the jar file, we can view this file. It has the following details
Manifest-Version: 1.0
The jar file can be run by the java application directly if has a manifest file with the header as Main-class. The Main-class header has the fully qualified name of the class which has the main(). This specifies the entry point of the application.
Illustration: Consider creating a JAR file with a manifest File called helloworld.MF
Manifest-Version : 1.0
Main-class : com.sample.test.HelloWorld
Example:
Java
// Importing the package
package com.sample.test;
// Main class
public class HelloWorld {
// Main driver method
public static void main(String[] args)
{
// Print statements only
System.out.println("Welcome to helloworld");
System.out.println("Jar file to be created");
}
}
Keep a note here m indicates the manifest file to be included while bundling into a jar file
Output:

Note: Here we compile the java file 'HelloWorld.java' using javac command. This command compiles the .java file and creates a class file HelloWorld.class. We then create the jar file helloworld.jar using jar command.
Lastly now while running the JAR file we use the below command to run the created jar file. When we run the jar file, 'Helloworld' class which has main() gets loaded by the JVM, and the code gets executed.
Similar Reads
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 compres
3 min read
Java.lang.Runtime class in Java In Java, the Runtime class is used to interact with Every Java application that has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime() method. Methods of Java
6 min read
Working with JAR and Manifest Files In Java A Jar file stands for Java archives, it is a compressed archive that contains the Java classes, libraries, metadata, and other files such as media data, audio, video, and documents. When we want to distribute a version of the software or distribute a single file, and not a directory structure filled
6 min read
Java.util.jar.JarEntry class in Java This class is used to represent a JAR file entry. Constructors : JarEntry(JarEntry je) : Creates a new JarEntry with fields taken from the specified JarEntry object. JarEntry(String name) : Creates a new JarEntry for the specified JAR file entry name. JarEntry(ZipEntry ze) : Creates a new JarEntry w
2 min read
JRE in Java Java Runtime Environment (JRE) is an open-access software distribution that has a Java class library, specific tools, and a separate JVM. In Java, JRE is one of the interrelated components in the Java Development Kit (JDK). It is the most common environment available on devices for running Java prog
4 min read
How to Add JAR file to Classpath in Java? JAR is an abbreviation of JAVA Archive. It is used for aggregating multiple files into a single one, and it is present in a ZIP format. It can also be used as an archiving tool but the main intention to use this file for development is that the Java applets and their components(.class files) can be
4 min read