如何在java中提取.war文件? ZIP与JAR [英] How to extract .war files in java? ZIP vs JAR
问题描述
我有一个网络程序,我希望用户能够导入 .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屋!