As of August 2017 and IntelliJ V2017.2, the accepted answer does not seem to be entirely accurate anymore: there is no fernflower.jar to use.
The jar file is called java-decompiler.jar and does not include a main manifest... Instead you can use the following command (from a Mac install):
java -cp "/Applications/IntelliJ IDEA.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler
(you will get the wrong Usage command, but it does work).
Answer from yan on Stack OverflowAs of August 2017 and IntelliJ V2017.2, the accepted answer does not seem to be entirely accurate anymore: there is no fernflower.jar to use.
The jar file is called java-decompiler.jar and does not include a main manifest... Instead you can use the following command (from a Mac install):
java -cp "/Applications/IntelliJ IDEA.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler
(you will get the wrong Usage command, but it does work).
Follow instructions for IntelliJ JD plugin. Or see an excerpt from the instructions below.
java -jar fernflower.jar [<source>]+ <destination>
+means 1 or more times
<source>: file or directory with files to be decompiled. Directories are recursively scanned. Allowed file extensions are class, zip and jar.
<destination>: destination directory
Example:
java -jar fernflower.jar -hdc=0 -dgs=1 -rsy=1 -lit=1 c:\Temp\binary\ -e=c:\Java\rt.jar c:\Temp\source\
Be aware that if you pass it a ".jar" file for the source, it will create another ".jar" file in the destination, however, within the new ".jar" file, the files will be .java instead of .class files (it doesn't explode the jar).
UPDATE
People ask me: How do I get the fernflower.jar?
If you have any IntelliJ product installed, chances are that you already have the Fernflower decompiler on your computer. IntelliJ IDEA comes with Java Bytecode Decompiler plugin (bundled) which is a modern extension of Fernflower.
- Locate the file in
${IntelliJ_INSTALL_DIR}\plugins\java-decompiler\lib\java-decompiler.jar(example: C:\Program Files\JetBrains\IntelliJ IDEA 2018\plugins\java-decompiler\lib). - Copy it somewhere and rename to fernflower.jar (optional).
This JAR is not executable, so we can't run it using
java -jar. However something like this works:java -cp fernflower.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler [<source>]+ <destination>org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompileris the class that contains the main method to run the decompiler.Example:
mkdir output_src java -cp fernflower.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -hdc=0 -dgs=1 -rsy=1 -lit=1 ./input.jar ./output_src
If you don't have IntelliJ products installed, either download it now (available on jetbrains.com) or make your own decompiler executable from sources (available on Github).
Fernflower and IntelliJ IDEA's java-decompiler - Stack Overflow
Visually Edit Decompiled Class File?
New open source Java decompiler
Looking for a Java decompiler
Videos
Try to invoke main class org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler manually
java -cp java-decompiler.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler myclassfile.class .
Also you can find more about internal usage of Fernflower inside IDEA by query in source code https://github.com/JetBrains/intellij-community/search?utf8=%E2%9C%93&q=Fernflower
You can get it looking at JetBrains releases: https://www.jetbrains.com/intellij-repository/releases/
Download the java-decompiler-engine.jar which will actually have the version name, but for simplicity I'll save it as c:\t\dl\jde.jar on my pc.
Then this for example will decompile the jar file for the game Necesse where I have it installed on my PC. The output seems to go into a jar file with the same name in the directory specified, here creating c:\t\Necesse.jar with the .java files in it (command split into lines for readability):
java -cp c:\t\dl\jde.jar
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler
'c:\games\steam\steamapps\common\Necesse\Necesse.jar'
c:\t
I'm working with Minecraft source code, which is a massive library of decompiled files all stored as .class files. I often find myself struggling to understand the code with some of the decompiler's additions, such as casting an object four times in a single block. Some variables are also unnamed, and I have to keep track of what some unnamed variables mean on a pad of paper.
I obviously don't mean to edit the content of the class file and how it functions directly, but since IDEA opens the files in read-only mode, I can't even make notes or anything.
Is there any way to visually edit a decompiled file's text in the editor without changing the file itself? (Preferably without having to make a copy of the file in your own source code.)
Hello! Today I'm happy to announce the release of a project that me and my friends have been working on over the course of the last year, Quiltflower! 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. After many frustrations with it myself with its decompiled code structuring and quality I decided to do something about it, and here we are! 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. We'd greatly appreciate it if you'd give it a try, with our Intellij Plugin, as a standalone jar, or on our maven. While it has come a long way it's still a work in progress, and feedback can be reported on our issue tracker.
Here's a comparison of Fernflower and Quiltflower's output.
I'd also like to thank the MinecraftForge Team for creating ForgeFlower, the fork that QuiltFlower was based on, and Lee Benfield for creating CFR and it's truly incredible test suite.