344

Does anyone know of a free decompiler that can decompile an entire Jar file instead of a single class? I have a problem with sub classes like name$1.class name$2.class name.class

7
  • 147
    Remember two more things: 1) The mere mention of a decompiler will cause the "holier than thou's" to come out and make value judgements about your motives despite having no idea what your planned use is, so be careful who you talk to. 2) The fancy JavaDecompiler will give you an excellent rendition of the code, well laid out and easy to read - missing only comments. It is astoundingly good, recovering a JAR file which had long lost source complete with variable names. Of course we don't obfuscate our in-house JAR files.
    – Andrew
    Feb 9, 2010 at 3:32
  • 1
    See also remarks in post Choose and test java decompiler.
    – dma_k
    Jan 2, 2012 at 12:19
  • 10
    I've stopped by this thread so many times when I needed to study how someone accomplished something for a Bukkit plugin... That comment always leaves me with a smile. I wish I could upvote it every time I stop by.
    – Jane Panda
    Apr 3, 2012 at 19:45
  • Simple online decompiler if you don't want to download any software. javadecompilers.com Nov 11, 2016 at 19:27
  • 1
    This shouldn't be closed as the decompilers playground changes dynamically. Currently, the best is probably FernFlower. If you're looking for an easy solution, download Windup and run it's command-line version on your .jar. It will decompile using FernFlower, with support up to Java 8 (jad only suports up to Java 1.3, JavaDecompiler up to Java 1.5 IIRC), with a fallback to Procyon if FernFlower fails. Feb 8, 2017 at 23:34

8 Answers 8

374

2023: splashout suggests in the comments the Vineflower/vineflower decompiler (releases), renaming from Quiltflower to Vineflower.

java -jar vineflower.jar -dgs=1 c:\Temp\binary\library.jar c:\Temp\souce

2022 update: QuiltMC/quiltflower is the latest most advanced Java decompiler:

Quiltflower is a modern, general purpose decompiler focused on improving code quality, speed, and usability.
Quiltflower is a fork of Fernflower and Forgeflower.

Changes include:

  • New language features (Try with resources, switch expressions, pattern matching, and more)
  • Better control flow generation (loops, try-catch, and switch, etc.)
  • More configurability
  • Better error messages
  • Javadoc application
  • Multithreading
  • Optimization
  • Many other miscellaneous features and fixes

Originally intended just for use with the QuiltMC toolchain with Minecraft, Quiltflower quickly expanded to be a general purpose java decompiler aiming to create code that is as accurate and clean as possible.

If the name sounds familiar it's because Quiltflower is a fork of Fernflower, the (in)famous decompiler that was developed by Stiver, maintained by Jetbrains, and became the default decompiler in Intellij IDEA.
Fernflower also quickly found its way into many other tools.

Over the past year, Quiltflower has added support for features such as modern string concatenation, a code formatter, sealed classes, pattern matching, switch expressions, try-with-resources, and more. Quiltflower also focuses on the code quality of the decompiled output, and takes readability very seriously.

See output examples.

Runs nice with jbang

https://github.com/QuiltMC/quiltflower/releases/download/1.8.1/quiltflower-1.8.1.jar

Or:

java -jar quiltflower.jar -dgs=1 c:\Temp\binary\library.jar c:\Temp\binary\Boot.class c:\Temp\source\

2009: JavaDecompiler can do a good job with a jar: since 0.2.5, All files, in JAR files, are displayed.

http://java.decompiler.free.fr/sites/default/screenshots/screenshot1.png

See also the question "How do I “decompile” Java class files?".

The JD-Eclipse doesn't seem to have changed since late 2009 though (see Changes).
So its integration with latest Eclipse (3.8, 4.2+) might be problematic.

JD-Core is actively maintained.

Both are the result of the fantastic work of (SO user) Emmanuel Dupuy.


2018: A more modern option, mentioned in the comments by David Kennedy Araujo:

JetBrains/intellij-community/plugins/java-decompiler/engine

Fernflower is the first actually working analytical decompiler for Java and probably for a high-level programming language in general.

java -jar fernflower.jar [-<option>=<value>]* [<source>]+ <destination>

java -jar fernflower.jar -hes=0 -hdc=0 c:\Temp\binary\ -e=c:\Java\rt.jar c:\Temp\source\

See also How to decompile to java files intellij idea for a command working with recent IntelliJ IDEA.


2022 update: Florian Wendelborn suggests in the comments

this one works well: jdec.app from Leonardo Santos.

17
41

First of all, it's worth remembering that all Java archive files (.jar/.war/etc...) are all basically just fancy.zip files, with a few added manifests and metadata.

Second, to tackle this problem I personally use several tools which handle this problem on all levels:

  • Jad + Jadclipse while working in IDE for decompiling .class files
  • WinRAR, my favorite compression tool natively supports Java archives (again, see first paragraph).
  • Beyond Compare, my favorite diff tool, when configured correctly can do on-the-fly comparisons between any archive file, including jars. Well worth a try.

The advantage of all the aforementioned, is that I do not need to hold any other external tool which clutters my work environment. Everything I will ever need from one of those files can be handled inside my IDE or diffed with other files natively.

0
38

If you happen to have both a bash shell and jad:

JAR=(your jar file name)
unzip -d $JAR.tmp $JAR
pushd $JAR.tmp
for f in `find . -name '*.class'`; do
    jad -d $(dirname $f) -s java -lnc $f
done
popd

I might be a tiny, tiny bit off with that, but it should work more or less as advertised. You should end up with $JAR.tmp containing your decompiled files.

3
  • 1
    on ubuntu use #!/bin/bash instead of #!/bin/sh becausw pushd doesnt work for the default ubuntu shell...
    – mossplix
    Aug 19, 2011 at 15:18
  • 1
    I'm using javap within this basic loop structure, and it's working for me. May 15, 2017 at 20:22
  • @mossplix or use /bin/sh (more portable) with cd and cd -, which is enough for this use case :-)
    – ljrk
    Mar 6, 2021 at 13:54
28

I have had reasonable success with a tool named (frustratingly) "JD: Java Decompiler".

I have found it better than most decompilers when dealing with classes compiled for Java 5 and higher. Unfortunately, it can still have some hiccups where JAD would normally succeed.

2
  • I couldn't download Windows or Linux version of JD-GUI. Is this problem only appears to me?
    – mmdemirbas
    Jul 24, 2012 at 8:53
  • @JanusTroelsen I deleted it. Thank you for notifying it. Lets keep answers clean :)
    – pramodc84
    Jun 13, 2013 at 3:35
14

Something like:

jar -xf foo.jar && find . -iname "*.class" | xargs /opt/local/bin/jad -r

maybe?

2
  • 1
    I've used jad for a while and needed a quick way to extract and decompile a whole jar. Thanks, this helped immensely. Jul 27, 2012 at 17:50
  • Worked immediately
    – Joel Wembo
    Sep 7, 2022 at 7:41
5

Insert the following into decompile.jar.sh

# Usage: decompile.jar.sh some.jar [-d]

# clean target folders
function clean_target {
  rm -rf $unjar $src $jad_log
}

# clean all debug stuff
function clean_stuff {
  rm -rf $unjar $jad_log
}

# the main function
function work {
  jar=$1
  unjar=`basename $jar.unjar`
  src=`basename $jar.src`
  jad_log=jad.log

  clean_target

  unzip -q $jar -d $unjar
  jad -d $src -ff -r -lnc -o -s java $unjar/**/*.class > $jad_log 2>&1

  if [ ! $debug ]; then
    clean_stuff
  fi

  if [ -d $src ] 
    then
      echo "$jar has been decompiled to $src"
    else
      echo "Got some problems check output or run in debug mode"
  fi
}

function usage {
  echo "This script extract and decompile JAR file"
  echo "Usage: $0 some.jar [-d]"
  echo "    where: some.jar is the target to decompile"
  echo "    use -d for debug mode"
}

# check params
if [ -n "$1" ]
  then
    if [ "$2" == "-d" ]; then
      debug=true
      set -x
    fi
    work $1
  else
    usage
fi
  • chmod +x decomplie.jar.sh //executable
  • ln -s ./decomplie.jar.s /usr/bin/dj

Ready to use, just type dj your.jar and you will get your.jar.src folder with sources. Use -d option for debug mode.

2
  • Thanks, but had to change "jad" to "./jad" on line 23 and run "bash decompile.jar.sh foo.jar -d" as I did not want to pollute my bin folder
    – Sam
    Mar 2, 2015 at 10:55
  • any recompiler ? recompiles jad files into jar ?
    – N Jay
    Jun 23, 2015 at 0:14
1

Note: This solution only works for Mac and *nix users.

I also tried to find Jad with no luck. My quick solution was to download MacJad that contains jad. Once you downloaded it you can find jad in [where-you-downloaded-macjad]/MacJAD/Contents/Resources/jad.

0

You extract it and then use jad against the dir.

2
  • I don't think you can just run it against the dir. You will have to specify {dir}/**/*.class
    – Vihung
    Feb 17, 2012 at 4:51
  • Extract the jar and use something like jad {dir}, I have just tested it and doesn't work on windows Apr 15, 2013 at 19:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.