java 如何在 Netbeans 中打开 JAR 进行编辑

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30422325/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:05:57  来源:igfitidea点击:

How can I open a JAR for editing in Netbeans

javajar

提问by user3377627

I made a JAR file. That runs fine. I've been tinkering with the source and I forgot what changes were made. Now that is not working. Can I pull the .java from the Jar somehow?

我做了一个 JAR 文件。那运行良好。我一直在修补源代码,但忘记了进行了哪些更改。现在这是行不通的。我可以以某种方式从 Jar 中提取 .java 吗?

回答by D. Visser

A JAR only contains .class files, which are compiled from .java source files. Unfortunately you can't edit the .class files and expect anything useful to come out of it.

JAR 仅包含从 .java 源文件编译的 .class 文件。不幸的是,您无法编辑 .class 文件并期望从中产生任何有用的信息。

This might work, though: JD GUI, a JAR decompiler.

不过,这可能有效:JD GUI,JAR 反编译器。

回答by bakalolo

A jar file is similar to a zip file in that you can extract the contents. From the oracle website to extract from the command line (you can also use a program like 7zip):

jar 文件类似于 zip 文件,您可以提取内容。从oracle网站到命令行解压(也可以用7zip之类的程序):

The basic command to use for extracting the contents of a JAR file is:

用于提取 JAR 文件内容的基本命令是:

jar xf  jar-file [archived-file(s)]

Let's look at the options and arguments in this command:

让我们看看这个命令中的选项和参数:

The x option indicates that you want to extract files from the JAR archive.
The f options indicates that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.
The jar-file argument is the filename (or path and filename) of the JAR file from which to extract files.
archived-file(s) is an optional argument consisting of a space-separated list of the files to be extracted from the archive. If this argument is not present, the Jar tool will extract all the files in the archive.

NOTE: A jar file can contain anytype of files and not just .class files.

注意:jar 文件可以包含任何类型的文件,而不仅仅是 .class 文件。

回答by Amit.rk3

extracting jar will give you just .class files. Still you can try java decompilerswhich can generate the source from .class files

解压 jar 只会给你 .class 文件。您仍然可以尝试java 反编译器,它可以从 .class 文件生成源代码

results are not 100% guaranteed though

虽然结果不能 100% 保证