command line
jar file
extraction
Java
tutorial

Extracting .jar file with command line

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

A .jar file is a Java archive, and in practice it is a ZIP-format container with a different extension. That means you can extract it from the command line either with Java's jar tool or with ordinary archive tools such as unzip.

Use The jar Command

If you have a JDK installed, the most direct command is:

bash
jar xf app.jar

Run that command in the directory where you want the contents to be unpacked. The x means extract, and the f means the next argument is the archive file.

This recreates the internal directory structure of the JAR in the current working directory.

List Contents Before Extracting

It is often useful to inspect the archive first.

bash
jar tf app.jar

That prints the file list without extracting anything. It is the quickest way to confirm whether the JAR contains compiled classes, configuration files, META-INF/MANIFEST.MF, or nested libraries.

Extract To A Separate Directory

Because jar xf writes into the current directory, a common pattern is to create a destination folder first.

bash
mkdir unpacked-jar
cd unpacked-jar
jar xf ../app.jar

This keeps extracted files isolated and avoids scattering package directories into whatever folder you happened to be using.

Use unzip When Java Tools Are Not Handy

Since a JAR is structurally a ZIP archive, standard ZIP tooling also works.

bash
unzip app.jar -d unpacked-jar

This is especially convenient on systems where unzip is already present and you do not need any Java-specific behavior.

What You Usually Find Inside

A normal library JAR often contains package directories full of .class files plus metadata under META-INF. An executable Spring Boot fat JAR may also contain directories such as BOOT-INF/classes and BOOT-INF/lib.

That matters because extracting a JAR does not decompile Java classes into source code. You will still see compiled .class files unless the archive also includes sources or resources.

Windows Command Line Options

On Windows, the same jar xf app.jar command works if Java is on your PATH. PowerShell users can also use general archive tooling, but the JDK command is usually the most predictable way to unpack a JAR when you are already working in a Java environment.

When Extraction Is Useful

Command-line extraction is helpful when you need to inspect the manifest, verify packaged resources, confirm dependency layout, or debug build output. It is also useful for comparing two builds to see what changed inside the artifact.

For example, after extraction you might inspect the manifest:

bash
cat META-INF/MANIFEST.MF

That can reveal the main class, build metadata, or class-path entries depending on how the JAR was created.

Common Pitfalls

A common mistake is extracting the JAR in the wrong directory and then mixing unpacked package folders with unrelated project files. Create a clean destination directory first.

Another mistake is expecting extraction to produce Java source code. Most JARs contain compiled .class files, not .java files.

It is also easy to forget that some executable JARs contain nested dependency JARs rather than a single flat class tree. Extraction still works, but the structure may be more layered than expected.

Summary

  • Use jar xf app.jar to extract a JAR with the JDK tool.
  • Use jar tf app.jar to inspect contents before extraction.
  • 'unzip also works because a JAR is a ZIP-format archive.'
  • Extract into a separate directory to keep the output clean.
  • Expect compiled classes and metadata, not necessarily source code.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.