

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is a JAR file?
A java archive file is a file format/ archiving tool which contains all the components of an executable Java application. All the predefined libraries are available in this format.
To include any of these (other than rt.jar) in to your project you need to set the class path for this particular JAR file. You can create a JAR file using the command line options or using any IDE’s.
Creating a Jar file
You can create a Jar file using the jar command as shown below.
jar cf jar-file input-file(s)
Let us consider an example, create a Sample Java program with name Sample.java
Sample.java
public class Sample { public static void main(String args[]){ System.out.println("Hi welcome to Tutorialspoint"); } }
If you compile this program using Javac command as shown below −
C:\Examples >javac Sample.java
This command compiles the given java file and generates a .class file (byte code)

Now, create a jar file for the generated class as −
C:\Sample>jar cvf sample.jar *.class added manifest adding: Sample.class(in = 434) (out= 302)(deflated 30%)
This will generate a jar file for all the classes in the current directory (since we used * instead of name) with specified name.

- Related Questions & Answers
- How to create a JAR file?
- How to make seleinum jar file , and how to test using Selenium jar file?
- Upload a non-maven jar file file to a server using jenkins
- What is a Multi-Release jar(mrjar) in Java 9?
- Error connecting SAP while sapjco3.jar file is in my library path
- How to run a JAR file through command prompt in java?
- How to deploy JSTL .jar file in CodingGround JSP emulator?
- What is the use of a multi-version compatible jar in Java 9?
- Dot.odp to pdf/docx file conversion in Java using tika jar files
- What is a Distributed File System (DFS)?
- Jar files in Java
- How can we create a multi-release jar(mrjar) using jar tool in Java 9?
- What is a file descriptor used in Python?
- What is a TestNG xml file in TestNG?
- What is HTML5 file Blob.slice() method