n1ghtk1n9
n1ghtk1n9

Reputation: 13

How to open a .jar file within Java

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?

Upvotes: 1

Views: 1878

Answers (1)

Nicolas Rinaudo
Nicolas Rinaudo

Reputation: 6168

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.

Upvotes: 1

Related Questions