如何在java中提取.war文件?ZIP 与 JAR [英] How to extract .war files in java? ZIP vs JAR
问题描述
我有一个 Web 程序,我希望用户能够在其中导入 .war
文件,并且我可以从 .war
文件中提取某些文件.我发现了两个类库:java.util.zip.*
和 java.util.jar.*
.据我了解,WAR 文件是一个特殊的 JAR 文件,它是一个特殊的 ZIP 文件.那么使用 java.util.jar
会更好吗?如果 ZIP 和 JAR 文件几乎相同,为什么需要两个不同的库?
I have a web program where I want the user to be able to import a .war
file and I can extract certain files out of the .war
file. I have found two class libraries: java.util.zip.*
and java.util.jar.*
. From what I understand, a WAR file is a special JAR file which is a special ZIP file. So would it be better to use java.util.jar
? If ZIP and JAR files are pretty much the same why is there a need for two different libraries?
推荐答案
如果看JarFile API 你会看到它是 ZipFile 类.
If you look at the JarFile API you'll see that it's a subclass of the ZipFile class.
jar 特定的类大多只是添加 jar 特定的功能,例如对清单文件属性的直接支持等.
The jar-specific classes mostly just add jar-specific functionality, like direct support for manifest file attributes and so on.
这是OOP在行动";由于 jar 文件是 zip 文件,因此 jar 类可以使用 zip 功能并提供额外的实用程序.
It's OOP "in action"; since jar files are zip files, the jar classes can use zip functionality and provide additional utility.
这篇关于如何在java中提取.war文件?ZIP 与 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!