如何在Java中打开一个.jar文件 [英] How to open a .jar file within Java

查看:199
本文介绍了如何在Java中打开一个.jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试着制作一个程序,很明显,打开一个.zip文件并将其内容提取到.jar文件(minecraft.jar,用于修改Minecraft),但是找不到任何方法打开Java内的.jar文件这样做。打开一个.jar文件(不是运行它)并添加/删除.jar文件中的文件是可能的吗?

解决方案

@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆