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.
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:
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.
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.
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.
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:
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.jarto extract a JAR with the JDK tool. - Use
jar tf app.jarto inspect contents before extraction. - '
unzipalso 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
- Extremely slow startup of a Spring Cloud Stream Kafka application when using enable.idempotence true
- Failed Autowired of BuildProperties Spring Boot 2.1.5 eclipse
- Failed to auto-configure a DataSource 'spring.datasource.url' is not specified
- Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource Spring Boot
- Failed to configure a DataSource 'url' attribute is not specified and no embedded datasource could be configured
- Failed to construct kafka producer with Springboot
- Failed to execute goal org.apache.maven.pluginsmaven-compiler-plugin2.3.2compile default-compile
- Failed to install android-sdk java.lang.NoClassDefFoundError javax/xml/bind/annotation/XmlSchema

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack 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.