Java 你如何重新编译一个jar文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3350545/
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 do you recompile a jar file?
提问by Kyle
I took an old jar file and edited it. Now i have a folder that has all the files and I want to recompile them back to a jar file. How do i do this?
我拿了一个旧的 jar 文件并对其进行了编辑。现在我有一个包含所有文件的文件夹,我想将它们重新编译回 jar 文件。我该怎么做呢?
回答by Jon Skeet
Jar files aren't "compiled" in the normal sense of the word. But you just create one with the jar
command:
Jar 文件不是通常意义上的“编译”。但是您只需使用以下jar
命令创建一个:
jar cvf myfile.jar file1 file2 etc
You can use globbing as normal:
您可以正常使用通配符:
jar cvf ../myfile.jar *
Run jar -?
or read the docsfor more information.
运行jar -?
或阅读文档以获取更多信息。
Note that for an executable jar file, you'll need to specify the manifest file as well.
请注意,对于可执行 jar 文件,您还需要指定清单文件。
回答by stacker
Jar files usually contain compiled java files (class-files) and resources. If you are allowed to make changes on this jar, you could disassemble the class files using JADand after recompilation assemble them again with the command jar
Jar 文件通常包含已编译的 java 文件(类文件)和资源。如果允许您对这个 jar 进行更改,您可以使用JAD反汇编类文件,并在重新编译后使用命令jar再次组装它们
How did you edit a jar file, hex editor?
你是如何编辑 jar 文件的,十六进制编辑器?
回答by Thorbj?rn Ravn Andersen
A jar file is just a zip file with a few extra files. You Can use any zip utility to rejar an unjarred jar file.
jar 文件只是一个带有一些额外文件的 zip 文件。您可以使用任何 zip 实用程序来 rejar 解压的 jar 文件。
回答by OscarRyz
How did you edit it?
你是怎么编辑的?
Anyway, jar
files follow the same format as regular zip
files. If you want to update the content of the jar ( probably with a new file ) you could do:
无论如何,jar
文件遵循与常规zip
文件相同的格式。如果你想更新 jar 的内容(可能是一个新文件),你可以这样做:
jar -uf yourJar.jar path/to/updated/Class.class
That would update your jar with the file path/to/updated/Class.class
If there's already a class with that name in that path, it would be replaced. If is not it would be created.
这将使用文件更新您的 jarpath/to/updated/Class.class
如果该路径中已经有一个具有该名称的类,它将被替换。如果不是,它将被创建。
After this your jar is up to date.
在此之后,您的 jar 是最新的。