CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > How to > How to Run JAR File: Step-by-Step Guide

Java Tutorial Menu

  • 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

How to Run JAR File: Step-by-Step Guide

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

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Published: January 11, 2021 · 3 min read · 2 Comments
Share: X in 🔗
java bat file to run jar

JAR (Java Archive) files bundle Java applications for easy distribution. But if you’re new to Java, running these files can be confusing—especially if double-clicking the JAR doesn’t work. In this guide, you’ll learn two foolproof methods to execute JAR files: using the command line and a batch script.

Table of Contents

  • Method 1: Run JAR File via Command Line
    • Step 1: Verify Java Installation
    • Step 2: Run the JAR File
    • Troubleshooting Tips
  • Method 2: Run JAR File Using a Batch Script
    • Step 1: Create the Batch File
    • Step 2: Run the Batch File
  • Conclusion

Method 1: Run JAR File via Command Line

The simplest way to run a JAR file is using the java -jar command. Here’s how:

Step 1: Verify Java Installation

First, ensure Java is installed on your system. Open Command Prompt (Windows) or Terminal (macOS/Linux) and run:

java -version

If the single hyphon – does not work then use double hyphon:

java --version

If either command shows the output like below:

openjdk 17.0.5 2022-10-18 LTS
OpenJDK Runtime Environment Corretto-17.0.5.8.1 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (build 17.0.5+8-LTS, mixed mode, sharing)

Note: If you have installed the other version of the JDK then you may see the different output.

If Java is not installed, then you can visit our guide to Install and Set Up Java Development Environment.

Step 2: Run the JAR File

  1. Navigate to the folder containing your JAR file using the cd command:
cd C:\path\to\jar\directory  
  1. Execute the JAR file with:
java -jar yourfile.jar  
  1. Replace yourfile.jar with your JAR’s actual name.

Troubleshooting Tips

  • “Java is not recognized”: Add Java to your system’s PATH variable.
  • “No main manifest attribute”: The JAR lacks a main class definition. Rebuild it with an entry point specified.

Method 2: Run JAR File Using a Batch Script

Batch files automate repetitive tasks. Create a batch script to run your JAR file with one click:

Step 1: Create the Batch File

  1. Open Notepad and paste this code:
@echo off  
java -jar "C:\path\to\yourfile.jar"  
pause  
  1. Replace the path with your JAR’s actual location.
  2. Save the file as run_jar.bat (select “All Files” as the type).

Note

The batch and bat words are used to refer same thing. The only difference is that, batch is the file format that holds some command to do some action and the bat is the extension of the batch file.

Note:

If you are creating the bat file using notepad then make sure to select Save as type: All. If you don’t do this, even you give the file name HelloWorld.bat it still saves the file as a text document.

Step 2: Run the Batch File

Double-click the run_jar.bat file. The JAR will execute, and the Command Prompt will stay open to display output/errors.

Pro Tip: Add the batch file to your desktop or taskbar for quick access.

Conclusion

You’ve now learned two reliable ways to run JAR file:

  1. Command Line: Use java -jar yourfile.jar for quick execution.
  2. Batch File: Automate the process with a one-click script.

For more Java tips, check out our guides on creating executable JARs and fixing common Java errors.

Related Posts:

  • Internationalization in Java
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • Setting Up an EC2 Instance with Amazon CloudFront…
  • Control Statements in Java
  • How to Create Executable JAR File (3 Methods Explained)
  • Command Line Arguments in Java
Tags:batch-filejarjavawindows
Was this article helpful?
← Previous ArticleWhat is MongoDB Atlas?
Next Article →How to create Windows Task Scheduler and run a Java application?

2 thoughts on “How to Run JAR File: Step-by-Step Guide”

  1. Someone
    July 19, 2022 at 12:18 pm

    thank you sir

    Log in to Reply
    • Coder Sathi
      July 19, 2022 at 1:53 pm

      Welcome. 🙂

      Log in to Reply

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • 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
  • Complete Guide to JaCoCo: How to Measure Java Code Coverage Accurately
CoderSathi

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

Quick Links

  • About
  • Contact

Popular Topics

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