What is a JAR file? – it’s easy to understand

blog img

A JAR (Java ARchive) file is a package file format used to bundle multiple files together into a single file, typically for Java applications. It is based on the ZIP file format and can contain Java class files, metadata, libraries, and resources like images or configuration files. JAR files are often used to distribute Java programs and libraries.

Key Features:

  1. Executable JARs: These contain a MANIFEST.MF file, specifying the main class to run, allowing you to execute the JAR as a standalone application using the java -jar command.
  2. Non-executable JARs: Used primarily as libraries that other applications or programs can include as dependencies.
  3. Compression: Since JARs use ZIP compression, the file size is smaller.

Examples of JAR Files:

  1. Executable JAR:
    • An application with a graphical user interface (GUI) or a command-line tool.
    • Example: MyApp.jar, which contains all Java class files, images, and other resources needed to run the app.
    • Command: java -jar MyApp.jar
  2. Library JAR:
    • A JAR file containing a set of classes used by other Java applications. These do not include an entry point (main method).
    • Example: mysql-connector-java.jar, which contains the JDBC driver to connect Java applications to a MySQL database.
  3. Web Application Archive (WAR):
    • Although technically a WAR is a web-specific archive, it’s based on the same JAR format.
    • Example: MyWebApp.war, used for packaging a Java web application with resources like HTML, JSP, and Servlet classes.
  4. Manifest Example:
    • A JAR file includes a META-INF/MANIFEST.MF file that may look like this:

making file

Manifest-Version: 1.0
Main-Class: com.example.Main

This specifies the entry point for an executable JAR.

Share your thoughts

Your email address will not be published. All fields are required.

Related post

  1. How to creating a JAR? – it’s easy.

    Creating a JAR file in Java involves compiling your Java…

  1. Top 50 Java Interview Questions and Answers.

    Here are the top 50 Java interview questions and answers…

  1. How to start creating Java class in Eclipse

    To create a Java class in Eclipse you need to…

  1. How to installation – Eclipse for Windows

    Download the Eclipse Installer from the official website of Eclipse…

  1. How to download Eclipse for Windows or macOS.

    Open your browser and type https://www.eclipse.org.The download page lists a…

Popular post

  1. Eclipse IDE – Create New Java Project.

    Opening the New Java Project…

  1. How to start the project in android studio

    Android Studio Open the Android…

  1. How to use ACOSH function in excel

    The ACOSH function returns the…

  1. Complete Header tags in html – easy to learn

    H tags can be used…

  1. Best features in Python programme – easy to learn

    Python is the most widely…