简体   繁体   English

如何从命令提示符将 jar 反编译为 .java 文件

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

如何从命令提示符将 JAR( .class二进制文件)反编译为.java源文件?

I found that jd-cmd does the job just fine, and works recursively in sub-folders for multiple files.我发现jd-cmd可以很好地完成这项工作,并且可以在多个文件的子文件夹中递归工作。 To decompile a group of files on the command line, run the following commands:要在命令行上反编译一组文件,请运行以下命令:

  1. Download the JAR file fromhere as the jd-cmd README.md file .这里下载 JAR 文件作为jd-cmd README.md文件
  2. Create the directory where your output Java files will be located.创建输出 Java 文件所在的目录。
  3. Run the command to decompile the files: java -jar jd-cli.jar -od <my-output-folder> <my-input-folder> .运行命令反编译文件: java -jar jd-cli.jar -od <my-output-folder> <my-input-folder>

in 2021, seems the command line is more simple:在 2021 年,命令行似乎更简单:

decompile target.jar to jar_result folder, and output the log with ALL levels.jar_result反编译到jar_result文件夹,输出ALL级别的日志。

$ jd-cli target.jar -od jar_result -g ALL

This GitHub project claims to be able to do so. 这个GitHub 项目声称能够做到这一点。 However, most people I know use JD-GUI .但是,我认识的大多数人都使用JD-GUI

JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core 是一个从一个或多个“.class”文件重构 Java 源代码的库。 JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. JD-Core 可用于恢复丢失的源代码并探索 Java 运行时库的来源。 New features of Java 5, such as annotations, generics or type “enum”, are supported.支持 Java 5 的新特性,例如注释、泛型或类型“枚举”。 JD-GUI and JD-Eclipse include JD-Core library. 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 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM