.jar文件和.war文件有什么区别? 仅仅是文件扩展名还是还有其他的东西?


当前回答

Jar:—Jar只包含.class War: War包含html, js, CSS和.class以及JSP和servlet页面

其他回答

War和jar是Java文件的存档。战争是网络档案,他们运行在网络服务器上。Jar是Java归档文件。

war文件是一个特殊的jar文件,用于打包web应用程序,使其易于部署到应用服务器上。war文件的内容必须遵循已定义的结构。

JAR文件允许打包多个文件,以便将其用作库、插件或任何类型的应用程序。另一方面,WAR文件仅用于web应用程序。

可以使用任何所需的结构创建JAR。相反,WAR具有预定义的WEB-INF和META-INF目录结构。

JAR文件允许Java运行时环境(JRE)在一个请求中部署整个应用程序,包括类和相关资源。另一方面,WAR文件允许轻松地测试和部署web应用程序。

战争——

分发基于java的web应用程序。WAR具有相同的文件 结构作为JAR文件,这是一个单独的压缩文件 包含多个捆绑在其中的文件。

Jar——

jar文件包含库、资源和附件文件 比如属性文件。 WAR文件用于组合jsp、servlet、Java类文件和XML 文件,javascript库,JAR库,静态网页等等 运行应用程序所需的其他资源。

You add web components to a J2EE application in a package called a web application archive (WAR), which is a JAR similar to the package used for Java class libraries. A WAR usually contains other resources besides web components, including: Server-side utility classes (database beans, shopping carts, and so on). Static web resources (HTML, image, and sound files, and so on) Client-side classes (applets and utility classes) A WAR has a specific hierarchical directory structure. The top-level directory of a WAR is the document root of the application. The document root is where JSP pages, client-side classes and archives, and static web resources are stored.

(源)

所以。war是一个。jar,但它包含web应用程序组件,并根据特定的结构进行布局。.war被设计为部署到web应用服务器(如Tomcat或Jetty)或Java EE服务器(如JBoss或Glassfish)。