问题
IDEA has a great built-in feature - decompiler. It works great.I can copy source code, but I cannot find option to extract all decompiled java classes to java files.
This project has a lot of java classes and packages, so I will be to long to copy this manually.
Does anyone know how to extract to java source files.
Thx
回答1:
To use the IntelliJ Java decompiler from the command line for a jar package follow the instructions provided here: https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine
回答2:
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).
回答3:
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.ConsoleDecompiler
is 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).
回答4:
You could use one of these (you can both use them online or download them, there is some info about each of them) : http://www.javadecompilers.com/
The one IntelliJ IDEA uses is fernflower, but it can't handle recent things - like String/Enum switches, generics (didn't test this one personally, only read about it), ... I just tried cfr from the above website and the result was the same as with the built-in decompiler (except for the Enum switch I had in my class).
回答5:
Try
https://github.com/fesh0r/fernflower
Download jar from
http://files.minecraftforge.net/maven/net/minecraftforge/fernflower/
Command :
java -jar fernflower.jar -hes=0 -hdc=0 C:\binary C:\source
Place your jar file in folder C:\binary and source will be extracted and packed in a jar inside C:\source.
Enjoy!
回答6:
The decompiler of IntelliJ IDEA was not built with this kind of usage in mind. It is only meant to help programmers peek at the bytecode of the java classes that they are developing. For decompiling lots of class files of which you do not have source code, you will need some other java decompiler, which is specialized for this job, and most likely runs standalone. If you google you should find a bunch.
回答7:
Some time ago I used JAD (JAva Decompiler) to achieve this - I do not think IntelliJ's decompiler was incorporated with exporting in mind. It is more of a tool to help look through classes where sources are not available.
JAD is still available for download, but I do not think anyone maintains it anymore: http://varaneckas.com/jad/
There were numerous plugins for it, namely Jadclipse (you guessed it, a way to use JAD in Eclipse - see decompiled classes where code is not available :)).
回答8:
I use JD-GUI for extract all decompiled java classes to java files.
回答9:
Someone had gave good answers. I made another instruction clue step by step. First, open your studio and search. You can find the decompier is Fernflower.
Second, we can find it in the plugins directory.
/Applications/Android Studio.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar
Third, run it, you will get the usage
java -cp "/Applications/Android Studio.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler
Usage: java -jar fernflower.jar [-<option>=<value>]* [<source>]+ <destination>
Example: java -jar fernflower.jar -dgs=true c:\my\source\ c:\my.jar d:\decompiled\
Finally, The studio's nest options for decompiler list as follows according IdeaDecompiler.kt
-hdc=0 -dgs=1 -rsy=1 -rbr=1 -lit=1 -nls=1 -mpm=60 -lac=1
IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR to "0",
IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES to "1",
IFernflowerPreferences.REMOVE_SYNTHETIC to "1",
IFernflowerPreferences.REMOVE_BRIDGE to "1",
IFernflowerPreferences.LITERALS_AS_IS to "1",
IFernflowerPreferences.NEW_LINE_SEPARATOR to "1",
**IFernflowerPreferences.BANNER to BANNER,**
IFernflowerPreferences.MAX_PROCESSING_METHOD to 60,
**IFernflowerPreferences.INDENT_STRING to indent,**
**IFernflowerPreferences.IGNORE_INVALID_BYTECODE to "1",**
IFernflowerPreferences.VERIFY_ANONYMOUS_CLASSES to "1",
**IFernflowerPreferences.UNIT_TEST_MODE to if (ApplicationManager.getApplication().isUnitTestMode) "1" else "0")**
I cant find the sutialbe option for the asterisk items.
Hope these steps will make the question clear.
来源:https://stackoverflow.com/questions/28389006/how-to-decompile-to-java-files-intellij-idea