How to decompile a whole Jar file?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To decompile an entire JAR file, use a command-line decompiler like CFR, Procyon, or Fernflower that can process all .class files in one pass and output Java source files. A JAR is just a ZIP archive containing compiled .class bytecode, resource files, and a manifest. Decompilation reverses the compilation step, producing readable (though not identical) Java source code from the bytecode. This is useful for debugging third-party libraries, understanding legacy code, or auditing dependencies when no source is available.
Decompiler Comparison
Each decompiler handles different Java language features with varying quality. The right choice depends on the Java version of the bytecode you are working with.
| Decompiler | Type | Java Version Support | Strengths | Weaknesses |
| CFR | CLI | Up to Java 21+ | Best with modern Java (lambdas, records, sealed classes) | Slower on very large JARs |
| Procyon | CLI | Up to Java 8, partial 9+ | Clean output for Java 5-8 era code | Limited support for newer features |
| Fernflower | CLI/IDE | Up to Java 17+ | Bundled in IntelliJ IDEA, good structural accuracy | Output can be less readable |
| JD-GUI | GUI | Up to Java 12 | Visual browsing, drag-and-drop | No longer maintained, no modern Java |
| Vineflower | CLI | Up to Java 21+ | Active fork of Fernflower with improvements | Newer, smaller community |
Method 1: CFR (Recommended for Modern Java)
CFR is a single JAR file with no dependencies. Download it from the GitHub releases page and run:
CFR writes one .java file per class, preserving the package directory structure. The output directory will mirror the original package hierarchy:
Method 2: Procyon
Procyon works similarly to CFR and produces clean output for Java 5 through 8 bytecode:
Procyon is particularly good at reconstructing for-each loops, try-with-resources, and generics from older bytecode.
Method 3: Fernflower (IntelliJ's Decompiler)
Fernflower is the decompiler built into IntelliJ IDEA. You can use it standalone from the command line:
Alternatively, open any JAR directly in IntelliJ IDEA. The IDE decompiles classes on the fly as you navigate through them. To export all decompiled sources, right-click the JAR in the project explorer and select "Decompile to Java."
Method 4: Vineflower (Improved Fernflower Fork)
Vineflower is an actively maintained fork of Fernflower with better output quality:
It handles modern Java features like pattern matching, switch expressions, and text blocks better than the original Fernflower.
Method 5: JD-GUI (Visual Browsing)
JD-GUI is a graphical tool for browsing decompiled code interactively. It is useful for quick inspection rather than batch decompilation:
- Download JD-GUI from the project website.
- Open the JAR file (drag-and-drop or File > Open).
- Browse classes in the tree view on the left.
- To save all sources: File > Save All Sources. This exports a ZIP file containing the decompiled
.javafiles.
JD-GUI is no longer actively maintained and struggles with Java 13+ features. For modern codebases, use CFR or Vineflower instead.
Shell Script for Batch Decompilation
When you need to decompile multiple JAR files (e.g., all dependencies in a lib/ directory), a simple shell script automates the process:
Extracting Without Decompiling
Sometimes you need to inspect the raw contents of a JAR without decompiling the bytecode. Since a JAR is a ZIP file, standard tools work:
To inspect individual .class files at the bytecode level without decompiling to Java:
javap is included in the JDK. It shows the actual bytecode instructions, which is useful when decompiled Java source does not accurately represent the behavior.
Handling Obfuscated JARs
Many commercial applications run their bytecode through obfuscators like ProGuard, R8, or Zelix KlassMaster. Obfuscated code decompiles but is difficult to read:
Tips for working with obfuscated code:
- Use CFR with
--rename trueto get slightly more readable placeholder names. - Look at string constants and API calls. Obfuscators rarely encrypt string literals.
- Cross-reference with the JAR's
META-INF/MANIFEST.MFand any included mapping files (e.g.,proguard-mapping.txt). - Focus on the entry points (main class, servlet classes, Spring components) and trace outward.
Common Pitfalls
Expecting decompiled code to compile directly. Decompilers produce approximations of the original source. Inner classes, synthetic bridge methods, and compiler optimizations can produce code that looks correct but does not compile. Treat the output as a reading aid, not a build artifact.
Using JD-GUI for modern Java bytecode. JD-GUI has not been updated to handle Java 13+ features like text blocks, records, or sealed classes. Use CFR or Vineflower for any bytecode compiled with Java 11 or later.
Ignoring legal implications. Decompiling proprietary software may violate license agreements. Many commercial licenses explicitly prohibit reverse engineering. Check the license terms before decompiling, especially for redistribution.
Not including dependency JARs. Decompilers produce better output when they can resolve referenced classes. If the JAR depends on other libraries, provide them as additional inputs so the decompiler can resolve types correctly. In CFR, use --extraclasspath.
Confusing jar xf with decompilation. Extracting a JAR gives you .class files (bytecode), not .java files (source). You need a decompiler to convert bytecode back to readable Java.
Summary
- Use CFR for modern Java (lambdas, records, sealed classes) with
java -jar cfr.jar app.jar --outputdir ./out. - Use Procyon for clean decompilation of Java 5-8 era code.
- Use Fernflower or Vineflower when working inside IntelliJ IDEA or when structural accuracy matters.
- Use JD-GUI only for quick visual browsing of older bytecode.
- A JAR is just a ZIP file. Use
jar tfto list contents andjavap -cto inspect bytecode directly. - Decompiled code is an approximation. Do not expect it to compile without modifications.
- Always check license terms before decompiling proprietary software.

