Java .war 与 .ear 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1594667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:33:42  来源:igfitidea点击:

.war vs .ear file

javajakarta-eedeployment

提问by ria

What is the difference between a .war and .ear file?

.war 和 .ear 文件有什么区别?

采纳答案by elhoim

From GeekInterview:

来自GeekInterview

In J2EE application, modules are packaged as EAR, JAR and WAR based on their functionality

JAR: EJB modules which contain enterprise java beans (class files) and EJB deployment descriptor are packed as JAR files with .jar extenstion

WAR: Web modules which contain Servlet class files, JSP Files, supporting files, GIF and HTML files are packaged as JAR file with .war (web archive) extension

EAR: All above files (.jar and .war) are packaged as JAR file with .ear (enterprise archive) extension and deployed into Application Server.

在 J2EE 应用程序中,模块根据其功能被打包为 EAR、JAR 和 WAR

JAR:包含企业 Java bean(类文件)和 EJB 部署描述符的 EJB 模块被打包为带有 .jar 扩展名的 JAR 文件

WAR:包含 Servlet 类文件、JSP 文件、支持文件、GIF 和 HTML 文件的 Web 模块被打包为带有 .war(Web 存档)扩展名的 JAR 文件

EAR:以上所有文件(.jar 和 .war)都打包为带有 .ear(企业存档)扩展名的 JAR 文件并部署到应用服务器中。

回答by paxdiablo

WAR (web archive) files contain servlet class files, JSPs (Java servlet pages), HTML and graphical files, and other supporting files.

WAR(Web 存档)文件包含 servlet 类文件、JSP(Java servlet 页面)、HTML 和图形文件以及其他支持文件。

EAR (enterprise archive) files contain the WAR files along with the JAR files containing code.

EAR(企业归档)文件包含 WAR 文件以及包含代码的 JAR 文件。

There may be other things in those files but their basically meant for what they sound like they mean: WAR for web-type stuff, EAR for enterprise-type stuff (WARs, code, connectors et al).

这些文件中可能还有其他内容,但它们的基本含义是它们听起来的意思:WAR 用于 Web 类型的东西,EAR 用于企业类型的东西(WAR、代码、连接器等)。

回答by David Rabinowitz

war - web archive. It is used to deploy web applications according to the servlet standard. It is a jar file containing a special directory called WEB-INF and several files and directories inside it (web.xml, lib, classes) as well as all the HTML, JSP, images, CSS, JavaScript and other resources of the web application

战争 - 网络档案。它用于根据 servlet 标准部署 Web 应用程序。它是一个 jar 文件,其中包含一个名为 WEB-INF 的特殊目录以及其中的几个文件和目录(web.xml、lib、classes)以及 Web 应用程序的所有 HTML、JSP、图像、CSS、JavaScript 和其他资源

ear - enterprise archive. It is used to deploy enterprise application containing EJBs, web applications, and 3rd party libraries. It is also a jar file, it has a special directory called APP-INF that contains the application.xml file, and it contains jar and war files.

耳朵-企业档案。它用于部署包含 EJB、Web 应用程序和 3rd 方库的企业应用程序。它也是一个 jar 文件,它有一个名为 APP-INF 的特殊目录,其中包含 application.xml 文件,它包含 jar 和 war 文件。

回答by Rutesh Makhijani

A WAR (Web Archive)is a module that gets loaded into a Web containerof a Java Application Server. A Java Application Server has two containers (runtime environments) - one is a Web container and the other is a EJB container.

一个WAR(Web归档)是被加载到一个模块Web容器A的Java应用服务器。Java 应用服务器有两个容器(运行时环境)——一个是 Web 容器,另一个是 EJB 容器。

The Web containerhosts Web applications based on JSP or the Servlets API - designed specifically for web request handling - so more of a request/response style of distributed computing. A Web container requires the Web module to be packaged as a WAR file- that is a special JAR file with a web.xmlfile in the WEB-INFfolder.

Web容器基于JSP或Servlet的API主机的Web应用程序-用于网络请求处理专门设计-这样的一个多分布式计算请求/响应样式。Web 容器要求将 Web 模块打包为WAR 文件——这是一个特殊的 JAR 文件,web.xml文件WEB-INF夹中有一个文件。

An EJB containerhosts Enterprise java beans based on the EJB API designed to provide extended business functionality such as declarative transactions, declarative method level security and multiprotocol support - so more of an RPC style of distributed computing. EJB containers require EJB modules to be packaged as JAR files- these have an ejb-jar.xmlfile in the META-INFfolder.

一个EJB容器基于EJB的API旨在提供扩展的业务功能,如声明式事务,声明方法级别的安全性和多协议支持主机企业Java Beans -这样的更多的RPC风格的分布式计算。EJB 容器需要将 EJB 模块打包为JAR 文件——这些ejb-jar.xml文件在META-INF文件夹中。

Enterprise applicationsmay consist of one or more modules that can either be Web modules (packaged as a WAR file), EJB modules (packaged as a JAR file), or both of them. Enterprise applications are packaged as EAR files― these are special JAR files containing an application.xmlfile in the META-INFfolder.

企业应用程序可能由一个或多个模块组成,这些模块可以是 Web 模块(打包为 WAR 文件)、EJB 模块(打包为 JAR 文件),或两者兼有。企业应用程序被打包为EAR 文件——这些是特殊的 JARapplication.xml文件,在META-INF文件夹中包含一个文件。

Basically, EAR filesare a superset containing WAR filesand JAR files. Java Application Servers allow deployment of standalone web modules in a WAR file, though internally, they create EAR files as a wrapper around WAR files. Standalone web containers such as Tomcatand Jettydo not support EAR files ― these are not full-fledged Application servers. Web applications in these containers are to be deployed as WAR files only.

基本上,EAR 文件是一个包含WAR 文件JAR 文件的超集。Java 应用服务器允许在 WAR 文件中部署独立的 Web 模块,但在内部,它们创建 EAR 文件作为 WAR 文件的包装器。TomcatJetty等独立 Web 容器不支持 EAR 文件——这些不是成熟的应用程序服务器。这些容器中的 Web 应用程序只能部署为 WAR 文件。

In application servers, EAR files contain configurations such as application security role mapping, EJB reference mapping and context root URL mapping of web modules.

在应用程序服务器中,EAR 文件包含诸如应用程序安全角色映射、EJB 引用映射和 Web 模块的上下文根 URL 映射等配置。

Apart from Web modules and EJB modules, EAR files can also contain connector modules packaged as RAR files and Client modules packaged as JAR files.

除了 Web 模块和 EJB 模块之外,EAR 文件还可以包含打包为 RAR 文件的连接器模块和打包为 JAR 文件的客户端模块。

回答by Mark

Ear files provide more options to configure the interaction with the application server.

Ear 文件提供了更多选项来配置与应用程序服务器的交互。

For example: if the hibernate version of the application server is older than the one provided by your dependencies, you can add the following to ear-deployer-jboss-beans.xml for JBOSS to isolate classloaders and avoid conflicts:

例如:如果应用服务器的hibernate版本比你的依赖提供的版本旧,你可以在ear-deployer-jboss-beans.xml中为JBOSS添加以下内容来隔离类加载器,避免冲突:

<bean name="EARClassLoaderDeployer" class="org.jboss.deployment.EarClassLoaderDeployer">    
  <property name="isolated">true</property>
</bean>

or to src/main/application/META-INF/jboss-app.xml :

或者到 src/main/application/META-INF/jboss-app.xml :

<?xml version="1.0"?>
<jboss-app>
<loader-repository>
    loader=nameofyourear.ear
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</jboss-app> 

This will make sure that there is no classloader conflict between your application and the application server.

这将确保您的应用程序和应用程序服务器之间没有类加载器冲突。

Normally the classloader mechanism works like this:

通常类加载器机制是这样工作的:

When a class loading request is presented to a class loader, it first asks its parent class loader to fulfill the request. The parent, in turn, asks its parent for the class until the request reaches the top of the hierarchy. If the class loader at the top of the hierarchy cannot fulfill the request, then the child class loader that called it is responsible for loading the class.

当类加载请求提交给类加载器时,它首先要求其父类加载器满足请求。反过来,父级向其父级询问类,直到请求到达层次结构的顶部。如果层次结构顶部的类加载器无法满足请求,则调用它的子类加载器负责加载该类。

By isolating the classloaders, your ear classloader will not look in the parent (=JBoss / other AS classloader). As far is I know, this is not possible with war files.

通过隔离类加载器,您的耳朵类加载器将不会在父类(=JBoss / 其他 AS 类加载器)中查找。据我所知,这对战争文件是不可能的。

回答by simpleDev

Refer: http://www.wellho.net/mouth/754_tar-jar-war-ear-sar-files.html

参考:http: //www.wellho.net/mouth/754_tar-jar-war-ear-sar-files.html

tar (tape archives) - Format used is file written in serial units of fileName, fileSize, fileData - no compression. can be huge

tar (tape archives) - 使用的格式是以文件名、文件大小、文件数据的串行单位写入的文件 - 没有压缩。可能很大

Jar (java archive) - compression techniques used - generally contains java information like class/java files. But can contain any files and directory structure

Jar (java archive) - 使用的压缩技术 - 通常包含 java 信息​​,如 class/java 文件。但可以包含任何文件和目录结构

war (web application archives) - similar like jar files only have specific directory structure as per JSP/Servlet spec for deployment purposes

战争(Web 应用程序档案) - 类似于 jar 文件,仅具有用于部署目的的 JSP/Servlet 规范的特定目录结构

ear (enterprise archives) - similar like jar files. have directory structure following J2EE requirements so that it can be deployed on J2EE application servers. - can contain multiple JAR and WAR files

耳朵(企业档案) - 类似于 jar 文件。具有遵循 J2EE 要求的目录结构,以便它可以部署在 J2EE 应用程序服务器上。- 可以包含多个 JAR 和 WAR 文件

回答by user1884500

J2EE defines three types of archives:

J2EE 定义了三种类型的档案:

  1. Java Archives (JAR)A JAR file encapsulates one or more Java classes, a manifest, and a descriptor. JAR files are the lowest level of archive. JAR files are used in J2EE for packaging EJBs and client-side Java Applications.

  2. Web Archives (WAR)WAR files are similar to JAR files, except that they are specifically for web applications made from Servlets, JSPs, and supporting classes.

  3. Enterprise Archives (EAR)”An EAR file contains all of the components that make up a particular J2EE application.

  1. Java 档案 (JAR)一个 JAR 文件封装了一个或多个 Java 类、一个清单和一个描述符。JAR 文件是最低级别的存档。JAR 文件在 J2EE 中用于打包 EJB 和客户端 Java 应用程序。

  2. Web Archives (WAR)WAR 文件类似于 JAR 文件,不同之处在于它们专门用于由 Servlet、JSP 和支持类构成的 Web 应用程序。

  3. Enterprise Archives (EAR)“EAR 文件包含构成特定 J2EE 应用程序的所有组件。

回答by Joby Wilson Mathews

JAR Files

JAR 文件

A JAR (short for Java Archive) file permits the combination of several files into a single one. Files with the '.jar'; extension are utilized by software developers to distribute Java classes and various metadata. These also hold libraries and resource files, as well as accessory files (such as property files).

JAR(Java Archive 的缩写)文件允许将多个文件合并为一个。带有“.jar”的文件;扩展被软件开发人员用来分发 Java 类和各种元数据。这些还包含库和资源文件,以及附件文件(例如属性文件)。

Users can extract and create JAR files with Java Development Kit's (JDK) '.jar' command. ZIP tools may also be used.

用户可以使用 Java 开发工具包 (JDK) 的“.jar”命令提取和创建 JAR 文件。也可以使用 ZIP 工具。

JAR files have optional manifest files. Entries within the manifest file prescribe the JAR file's use. A 'main' class specification for a file class denotes the file as a detached or ‘stand-alone' program.

JAR 文件具有可选的清单文件。清单文件中的条目规定了 JAR 文件的使用。文件类的“主”类规范将文件表示为分离的或“独立的”程序。

WAR Files

WAR文件

A WAR (or Web Application archive) files can comprise XML (extensible Markup Language) files, Java classes, as well as Java Server pages for purposes of Internet application. It is also employed to mark libraries and Web pages which make up a Web application. Files with the ‘.war' extension contain the Web app for use with server or JSP (Java Server Page) containers. It has JSP, HTML (Hypertext Markup Language), JavaScript, and various files for creating the aforementioned Web apps.

WAR(或 Web 应用程序存档)文件可以包含 XML(可扩展标记语言)文件、Java 类以及用于 Internet 应用程序的 Java 服务器页面。它还用于标记构成 Web 应用程序的库和 Web 页面。带有“.war”扩展名的文件包含用于服务器或 JSP(Java 服务器页面)容器的 Web 应用程序。它具有 JSP、HTML(超文本标记语言)、JavaScript 和用于创建上述 Web 应用程序的各种文件。

A WAR file is structured as such to allow for special directories and files. It may also have a digital signature (much like that of a JAR file) to show the veracity of the code.

WAR 文件的结构允许特殊的目录和文件。它也可能有一个数字签名(很像 JAR 文件的签名)来显示代码的真实性。

EAR Files

EAR 文件

An EAR (Enterprise Archive) file merges JAR and WAR files into a single archive. These files with the ‘.ear' extension have a directory for metadata. The modules are packaged into on archive for smooth and simultaneous operation of the different modules within an app server.

EAR(企业档案)文件将 JAR 和 WAR 文件合并为一个档案。这些带有“.ear”扩展名的文件有一个元数据目录。这些模块被打包到存档中,以便应用服务器内不同模块的平滑和同时运行。

The EAR file also has deployment descriptors (which are XML files) which effectively dictate the deployment of the different modules.

EAR 文件还具有部署描述符(它们是 XML 文件),它们有效地规定了不同模块的部署。

enter image description here

在此处输入图片说明

回答by Ashish Kamble

To make the project transport, deployment made easy. need to compressed into one file. JAR (java archive) group of .class files

为了使项目运输、部署变得容易。需要压缩成一个文件。JAR(java 存档)组 .class 文件

WAR (web archive) - each war represents one web application - use only web related technologies like servlet, jsps can be used. - can run on Tomcat server - web app developed by web related technologies only jsp servlet html js - info representation only no transactions.

WAR (web archive) - 每个 war 代表一个 web 应用程序 - 只使用 web 相关技术,如 servlet、jsps 可以使用。- 可以在 Tomcat 服务器上运行 - 由 web 相关技术开发的 web 应用程序只有 jsp servlet html js - 信息表示只有没有事务。

EAR (enterprise archive) - each ear represents one enterprise application - we can use anything from j2ee like ejb, jms can happily be used. - can run on Glassfish like server not on Tomcat server. - enterprise app devloped by any technology anything from j2ee like all web app plus ejbs jms etc. - does transactions with info representation. eg. Bank app, Telecom app

EAR(企业档案)——每只耳朵代表一个企业应用——我们可以使用 j2ee 中的任何东西,比如 ejb,jms 可以愉快地使用。- 可以像服务器一样在 Glassfish 上运行,而不是在 Tomcat 服务器上运行。- 由 j2ee 任何技术开发的企业应用程序,如所有 Web 应用程序以及 ejbs jms 等。 - 使用信息表示进行交易。例如。银行应用、电信应用