Reputation: 739
How can I decompile a JAR (.class
binary files) into .java
source files from command prompt?
Upvotes: 25
Views: 90022
Reputation: 5331
The JD-CMD GitHub project claims to be able to do so. However, most people I know use JD-GUI.
JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type “enum”, are supported. JD-GUI and JD-Eclipse include JD-Core library.
I should include that when a source file is compiled, things like the variable assignment and the names of those variables are changed. Similarly, syntactic sugar is changed into what it actually is (such as x += i
turns into x = x + i
).
Upvotes: 5
Reputation: 21557
in 2021, seems the command line is more simple:
decompile target.jar to jar_result
folder, and output the log with ALL
levels.
$ jd-cli target.jar -od jar_result -g ALL
Upvotes: 7
Reputation: 10749
I found that jd-cmd does the job just fine, and works recursively in sub-folders for multiple files. To decompile a group of files on the command line, run the following commands:
README.md
file.java -jar jd-cli.jar -od <my-output-folder> <my-input-folder>
.Upvotes: 25