如何在Java中打开一个.jar文件 [英] How to open a .jar file within Java
问题描述
@McDowell注释是解决方案的根源: java.util.jar
包是您可以找到所需工具的位置。
$第二,尽快修改JAR文件的内容是可能的,但是复杂而且相当多的工作。如果我的理解是正确的,打开这两个文件(ZIP和JAR文件),将它们解压到一个临时目录,然后重新压缩整个文件,这样做是不够的吗?
在我看来,结果将是你正在寻找的。这可能需要一段时间才能运行,但由于这是一次性的,我不觉得这是一个主要问题。
I've been trying to make a program that, evidently, opens a .zip file and extracts its contents into a .jar file(minecraft.jar, for modding Minecraft), but couldn't find any way to open a .jar file within Java to do so. Is opening a .jar file(not running it) and adding/deleting files within the .jar file possible?
First, @McDowell comment is the root of your solution: the java.util.jar
package is where you'll find the tools you need.
Second, modifying the content of a JAR file on the fly is possible, but complicated and rather a lot of work. Would it not be sufficient for your purposes to open both files (the ZIP and JAR ones, if I understand correctly), extract them in a temporary directory, then re-compress the whole lot?
It seems to me the result would be exactly what you're looking for. It might take a bit of a while to run, but since it's a one-off, I don't feel it's a major issue.
这篇关于如何在Java中打开一个.jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!