如何从命令提示符将 jar 反编译为 .java 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35564270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to decompile a jar into .java files from command prompt
提问by Karuna
How can I decompile a JAR (.class
binary files) into .java
source files from command prompt?
如何从命令提示符将 JAR(.class
二进制文件)反编译为.java
源文件?
采纳答案by ifly6
ThisGitHub project claims to be able to do so. However, most people I know use JD-GUI.
这个GitHub 项目声称能够做到这一点。但是,我认识的大多数人都使用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.
JD-Core 是一个从一个或多个“.class”文件重构 Java 源代码的库。JD-Core 可用于恢复丢失的源代码并探索 Java 运行时库的来源。支持 Java 5 的新特性,例如注释、泛型或类型“枚举”。JD-GUI 和 JD-Eclipse 包含 JD-Core 库。
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
).
我应该包括在编译源文件时,诸如变量赋值和这些变量的名称之类的内容会发生变化。类似地,语法糖变成了它实际的样子(比如x += i
变成了x = x + i
)。
回答by entpnerd
I found that jd-cmddoes 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:
我发现jd-cmd可以很好地完成这项工作,并且可以在多个文件的子文件夹中递归工作。要在命令行上反编译一组文件,请运行以下命令:
- Download the JAR file from hereas 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>
.
- 从这里下载 JAR 文件作为jd-cmd
README.md
文件。 - 创建输出 Java 文件所在的目录。
- 运行命令反编译文件:
java -jar jd-cli.jar -od <my-output-folder> <my-input-folder>
.