Karuna
Karuna

Reputation: 739

How to decompile a jar into .java files from command prompt

How can I decompile a JAR (.class binary files) into .java source files from command prompt?

Upvotes: 25

Views: 90022

Answers (3)

ifly6
ifly6

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

Siwei
Siwei

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

Jon Thoms
Jon Thoms

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:

  1. Download the JAR file from here as the jd-cmd README.md file.
  2. Create the directory where your output Java files will be located.
  3. Run the command to decompile the files: java -jar jd-cli.jar -od <my-output-folder> <my-input-folder>.

Upvotes: 25

Related Questions