本文翻译自:Difference between jar and war in Java
What is the difference between a .jar and a .war file? .jar和.war文件有什么区别?
Is it only the file extension or is there something more? 它只是文件扩展名还是还有更多内容?
#1楼
参考:https://stackoom.com/question/OdKP/Java与jar之间的区别
#2楼
War - 战争 -
distribute Java-based web applications. 分发基于Java的Web应用程序。 A WAR has the same file structure as a JAR file, which is a single compressed file that contains multiple files bundled inside it. WAR具有与JAR文件相同的文件结构,JAR文件是单个压缩文件,其中包含捆绑在其中的多个文件。
Jar - 罐子 -
The .jar files contain libraries, resources and accessories files like property files. .jar文件包含库,资源和附件文件,如属性文件。
WAR files are used to combine JSPs, servlets, Java class files, XML files, javascript libraries, JAR libraries, static web pages, and any other resources needed to run the application. WAR文件用于组合JSP,servlet,Java类文件,XML文件,javascript库,JAR库,静态Web页面以及运行应用程序所需的任何其他资源。
#3楼
WAR stands for Web application ARchive WAR代表Web应用程序ARchive
JAR stands for Java ARchive JAR代表Java ARchive
#4楼
Jar : - jar只包含.class war : - war包含html,js,css和.class jsp和servlets页面
#5楼
JAR files allow to package multiple files in order to use it as a library, plugin, or any kind of application. JAR文件允许打包多个文件,以便将其用作库,插件或任何类型的应用程序。 On the other hand, WAR files are used only for web applications. 另一方面,WAR文件仅用于Web应用程序。
JAR can be created with any desired structure. 可以使用任何所需结构创建JAR。 In contrast, WAR has a predefined structure with WEB-INF and META-INF directories. 相比之下,WAR具有WEB-INF和META-INF目录的预定义结构。
A JAR file allows Java Runtime Environment (JRE) to deploy an entire application including the classes and the associated resources in a single request. JAR文件允许Java运行时环境(JRE)在单个请求中部署整个应用程序,包括类和相关资源。 On the other hand, a WAR file allows testing and deploying a web application easily. 另一方面,WAR文件允许轻松地测试和部署Web应用程序。
#6楼
A JAR file extension is .jar and is created with jar command from command prompt (like javac command is executed). JAR文件扩展名为.jar,使用命令提示符下的jar命令创建(如执行javac命令)。 Generally, a JAR file contains Java related resources like libraries, classes etc.JAR file is like winzip file except that Jar files are platform independent. 通常,JAR文件包含Java相关资源,如库,类等.JAR文件类似于winzip文件,但Jar文件与平台无关。
A WAR file is simply a JAR file but contains only Web related Java files like Servlets, JSP, HTML. WAR文件只是一个JAR文件,但只包含与Web相关的Java文件,如Servlet,JSP,HTML。
To execute a WAR file, a Web server or Web container is required, for example, Tomcat or Weblogic or Websphere. 要执行WAR文件,需要Web服务器或Web容器,例如Tomcat或Weblogic或Websphere。 To execute a JAR file, simple JDK is enough. 要执行JAR文件,简单的JDK就足够了。