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

3

25

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

Neuro answered 22/2, 2016 at 21:30 Comment(4)
You'll need to find a Java decompiler for that. Even then, it won't be the same as the .java files used to make it. Compiling is a one way street.Digestant
I tried using JD plugin but using that i can actually view .class files. so looking for compiling the .class jar files into .java files so that i can import them into my eclipse as project and debug on it.Neuro
@Neuro If it doesn't have to be command-line, I believe JD-GUI has an option to export a JAR of source files, which you can then un-JAR.Brassware
got it thanks immibis & resueman.Neuro
C
5

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).

Cardiology answered 22/2, 2016 at 21:31 Comment(0)
L
25

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>.
Livelihood answered 18/4, 2018 at 18:42 Comment(0)
B
7

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
Barcroft answered 17/3, 2021 at 6:14 Comment(0)
C
5

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).

Cardiology answered 22/2, 2016 at 21:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.