CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > How to Create Executable JAR File (3 Methods Explained)

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor
  • Home

How to Create Executable JAR File (3 Methods Explained)

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 3 min read · 0 Comments
Share: in X

An executable JAR (Java Archive) file lets you run a Java application with a single click or command. Unlike standard JARs, executable JARs include a main class defined in the MANIFEST.MF file, making them self-runnable. In this guide, you’ll learn three methods to create executable JARs—using the command line, Maven, and Eclipse IDE.

Table of Contents

  • Prerequisites
  • Method 1: Create Executable JAR via Command Line
    • Step 1: Write a Java Program
    • Step 2: Compile the Java File
    • Step 3: Create a Manifest File
    • Step 4: Build the Executable JAR
    • Step 5: Run the Executable JAR
  • Method 2: Create Executable JAR with Maven
    • Step 1: Configure the pom.xml File
    • Step 2: Build the JAR
  • Method 3: Create Executable JAR in Eclipse
    • Step 1: Export the Project as a JAR
    • Step 2: Define the Main Class
    • Step 3: Finish and Run
    • Demo Video
  • Troubleshooting Executable JAR Issues
    • 1. “No main manifest attribute”
    • 2. “Could not find or load main class”
  • Conclusion

Prerequisites

  • Java Development Kit (JDK) installed (version 8 or later).
  • Basic familiarity with Java programming.

Method 1: Create Executable JAR via Command Line

Step 1: Write a Java Program

Create a simple Java class with a main method. For example:

public class HelloWorld {  
    public static void main(String[] args) {  
        System.out.println("Hello, Executable JAR!");  
    }  
}  

Save it as HelloWorld.java.

Step 2: Compile the Java File

Open Terminal/Command Prompt and compile the code:

javac HelloWorld.java  

This generates HelloWorld.class.

Step 3: Create a Manifest File

The manifest defines the main class. Create a manifest.txt file with:

Main-Class: HelloWorld  

Note: Add a newline at the end of the file to avoid errors.

Make sure to save both HelloWorld.java and manifest.txt file in same location/folder.

Step 4: Build the Executable JAR

Run the jar command to bundle files:

jar cfm HelloWorld.jar manifest.txt HelloWorld.class  
  • c: Create a JAR.
  • f: Specify the JAR filename.
  • m: Include the manifest file.

Step 5: Run the Executable JAR

Test it with:

java -jar HelloWorld.jar  

Output: Hello, Executable JAR!

Method 2: Create Executable JAR with Maven

Step 1: Configure the pom.xml File

Add the Maven JAR Plugin to your project’s pom.xml:

<build>  
    <plugins>  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-jar-plugin</artifactId>  
            <version>3.3.0</version>  
            <configuration>  
                <archive>  
                    <manifest>  
                        <mainClass>com.codersathi.HelloWorld</mainClass>  
                    </manifest>  
                </archive>  
            </configuration>  
        </plugin>  
    </plugins>  
</build>  

Replace com.example.HelloWorld with your main class’s full package path.

Step 2: Build the JAR

Run:

mvn clean package  

The executable JAR will be generated in the target folder.

Method 3: Create Executable JAR in Eclipse

Step 1: Export the Project as a JAR

  1. Right-click your project > Export > Java > JAR File.
  2. Select resources to include and specify the JAR output path.

Step 2: Define the Main Class

  1. In the export wizard, click Next until you reach the JAR Manifest Specification screen.
  2. Check Generate the manifest file and specify your main class under Main Class.

Step 3: Finish and Run

Click Finish. Run the JAR via:

java -jar YourProject.jar  

Demo Video

Troubleshooting Executable JAR Issues

1. “No main manifest attribute”

  • Solution: Ensure the Main-Class is correctly defined in the manifest.

2. “Could not find or load main class”

  • Solution: Verify the main class’s package path matches the manifest entry.

Conclusion

You’ve now learned three ways to create an executable JAR file:

  1. Command Line: Ideal for small projects.
  2. Maven: Best for automated builds and dependency management.
  3. Eclipse: Perfect for IDE users.

For advanced use cases, explore creating fat JARs or bundling apps into native executables.

Need help? Check out our guide on how to run JAR files 

Related Posts:

  • User Defined Exception in Java
  • Step-by-Step Guide to Set Up Eclipse with Tomcat…
  • Command Line Arguments in Java
  • Install and Set Up Java Development Environment
  • How to Set Up JaCoCo Java Test Coverage in Maven…
  • Packages in Java: A Guide to Modular, Maintainable Code
Tags:how-tojava
Was this article helpful?
← Previous ArticleMost Frequently Asked Spring Boot Interview Questions for 2025
Next Article →How to Use QueryDSL in Spring Boot 3: A Complete Guide to Type-Safe Queries [2025 Update]

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap