How to decompile a jar into .java files from command prompt
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
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:
- Download the JAR file from here as the jd-cmd
README.md
file. - Create the directory where your output Java files will be located.
- Run the command to decompile the files:
java -jar jd-cli.jar -od <my-output-folder> <my-input-folder>
.
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
).