简体   繁体   English

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

[英]How can I open a JAR for editing in Netbeans

I made a JAR file. 我做了一个JAR文件。 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中拉出.java吗?

A JAR only contains .class files, which are compiled from .java source files. JAR仅包含.class文件,这些文件是从.java源文件编译而成的。 Unfortunately you can't edit the .class files and expect anything useful to come out of it. 不幸的是,您无法编辑.class文件,并且期望从中得到有用的东西。

This might work, though: JD GUI , a JAR decompiler. 但是,这可能会起作用: JD GUI ,一个JAR反编译器。

A jar file is similar to a zip file in that you can extract the contents. jar文件类似于zip文件,因为您可以提取其中的内容。 From the oracle website to extract from the command line (you can also use a program like 7zip): 从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 any type of files and not just .class files. 注意:jar文件可以包含任何类型的文件,而不仅仅是.class文件。

extracting jar will give you just .class files. 解压缩jar只会得到.class文件。 Still you can try java decompilers which can generate the source from .class files 仍然可以尝试使用Java反编译器 ,它可以从.class文件生成源代码

results are not 100% guaranteed though 虽然不能保证结果100%

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

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