简体   繁体   English

.war 与 .ear 文件

[英].war vs .ear file

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

A WAR (Web Archive) is a module that gets loaded into a Web container of a Java Application Server . WAR(Web Archive)是一个模块,它被加载到Java Application ServerWeb 容器中。 A Java Application Server has two containers (runtime environments) - one is a Web container and the other is a EJB container. Java 应用服务器有两个容器(运行时环境)——一个是 Web 容器,另一个是 EJB 容器。

The Web container hosts 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 . Web 容器承载基于 JSP 或 Servlets API 的 Web 应用程序(专为 Web 请求处理而设计),因此更像是分布式计算请求/响应样式 A Web container requires the Web module to be packaged as a WAR file - that is a special JAR file with a web.xml file in the WEB-INF folder. Web 容器要求将 Web 模块打包为WAR 文件——这是一个特殊的 JAR 文件,在WEB-INF文件夹中包含一个web.xml文件。

An EJB container hosts 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 容器承载基于 EJB API 的 Enterprise java bean,旨在提供扩展的业务功能,例如声明式事务、声明式方法级别安全性和多协议支持 - 因此更像是分布式计算RPC 样式 EJB containers require EJB modules to be packaged as JAR files - these have an ejb-jar.xml file in the META-INF folder. EJB 容器需要将 EJB 模块打包为JAR 文件- 这些文件在META-INF文件夹中有一个ejb-jar.xml文件。

Enterprise applications may 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.企业应用程序可能由一个或多个模块组成,这些模块可以是 Web 模块(打包为 WAR 文件)、EJB 模块(打包为 JAR 文件),或两者兼有。 Enterprise applications are packaged as EAR files ― these are special JAR files containing an application.xml file in the META-INF folder.企业应用程序被打包为EAR 文件——这些是特殊的 JAR 文件,在META-INF文件夹中包含一个application.xml文件。

Basically, EAR files are a superset containing WAR files and JAR files .基本上, EAR 文件是一个包含WAR 文件JAR 文件的超集。 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. Java 应用服务器允许在 WAR 文件中部署独立的 Web 模块,但在内部,它们创建 EAR 文件作为 WAR 文件的包装器。 Standalone web containers such as Tomcat and Jetty do not support EAR files ― these are not full-fledged Application servers. TomcatJetty等独立 Web 容器不支持 EAR 文件——这些不是成熟的应用程序服务器。 Web applications in these containers are to be deployed as WAR files only.这些容器中的 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 文件的客户端模块。

From GeekInterview :来自GeekInterview

In J2EE application, modules are packaged as EAR, JAR, and WAR based on their functionality在 J2EE 应用程序中,模块根据其功能打包为 EAR、JAR 和 WAR

JAR: EJB modules which contain enterprise java beans (class files) and EJB deployment descriptor are packed as JAR files with .jar extension JAR:包含企业 Java bean(类文件)和 EJB 部署描述符的 EJB 模块被打包为具有 .jar 扩展名的 JAR 文件

WAR: Web modules which contain Servlet class files, JSP Files, supporting files, GIF and HTML files are packaged as a JAR file with .war (web archive) extension WAR:包含 Servlet 类文件、JSP 文件、支持文件、GIF 和 HTML 文件的 Web 模块被打包为带有 .war(Web 存档)扩展名的 JAR 文件

EAR: All the above files (.jar and .war) are packaged as a JAR file with .ear (enterprise archive) extension and deployed into Application Server. EAR:以上所有文件(.jar 和 .war)都打包为带有 .ear(企业归档)扩展名的 JAR 文件并部署到应用服务器中。

war - web archive.战争 - 网络档案。 It is used to deploy web applications according to the servlet standard.它用于根据 servlet 标准部署 Web 应用程序。 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它是一个 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.它用于部署包含 EJB、Web 应用程序和 3rd 方库的企业应用程序。 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.它也是一个 jar 文件,它有一个名为 APP-INF 的特殊目录,其中包含 application.xml 文件,它包含 jar 和 war 文件。

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、代码、连接器等)。

JAR Files JAR 文件

A JAR (short for Java Archive) file permits the combination of several files into a single one. JAR(Java Archive 的缩写)文件允许将多个文件合并为一个。 Files with the '.jar';带有“.jar”的文件; extension are utilized by software developers to distribute Java classes and various metadata.扩展被软件开发人员用来分发 Java 类和各种元数据。 These also hold libraries and resource files, as well as accessory files (such as property files).这些还包含库和资源文件,以及附件文件(例如属性文件)。

Users can extract and create JAR files with Java Development Kit's (JDK) '.jar' command.用户可以使用 Java 开发工具包 (JDK) 的“.jar”命令提取和创建 JAR 文件。 ZIP tools may also be used.也可以使用 ZIP 工具。

JAR files have optional manifest files. JAR 文件具有可选的清单文件。 Entries within the manifest file prescribe the JAR file's use.清单文件中的条目规定了 JAR 文件的使用。 A 'main' class specification for a file class denotes the file as a detached or 'stand-alone' program.文件类的“主”类规范将文件表示为分离的或“独立的”程序。

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. WAR(或 Web 应用程序存档)文件可以包含 XML(可扩展标记语言)文件、Java 类以及用于 Internet 应用程序的 Java 服务器页面。 It is also employed to mark libraries and Web pages which make up a Web application.它还用于标记构成 Web 应用程序的库和 Web 页面。 Files with the '.war' extension contain the Web app for use with server or JSP (Java Server Page) containers.带有“.war”扩展名的文件包含用于服务器或 JSP(Java 服务器页面)容器的 Web 应用程序。 It has JSP, HTML (Hypertext Markup Language), JavaScript, and various files for creating the aforementioned Web apps.它具有 JSP、HTML(超文本标记语言)、JavaScript 和用于创建上述 Web 应用程序的各种文件。

A WAR file is structured as such to allow for special directories and files. WAR 文件的结构允许特殊的目录和文件。 It may also have a digital signature (much like that of a JAR file) to show the veracity of the code.它也可能有一个数字签名(很像 JAR 文件的签名)来显示代码的真实性。

EAR Files EAR 文件

An EAR (Enterprise Archive) file merges JAR and WAR files into a single archive. EAR(企业档案)文件将 JAR 和 WAR 文件合并为一个档案。 These files with the '.ear' extension have a directory for metadata.这些带有“.ear”扩展名的文件有一个元数据目录。 The modules are packaged into on archive for smooth and simultaneous operation of the different modules within an app server.这些模块被打包到存档中,以便应用服务器内不同模块的平滑和同时运行。

The EAR file also has deployment descriptors (which are XML files) which effectively dictate the deployment of the different modules. EAR 文件还具有部署描述符(它们是 XML 文件),它们有效地规定了不同模块的部署。

在此处输入图片说明

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. tar (tape archives) - 使用的格式是以文件名、文件大小、文件数据的串行单位写入的文件 - 没有压缩。 can be huge可能很大

Jar (java archive) - compression techniques used - generally contains java information like class/java files. Jar (java archive) - 使用的压缩技术 - 通常包含 java 信息​​,如 class/java 文件。 But can contain any files and directory structure但可以包含任何文件和目录结构

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.耳朵(企业档案) - 类似于 jar 文件。 have directory structure following J2EE requirements so that it can be deployed on J2EE application servers.具有遵循 J2EE 要求的目录结构,以便它可以部署在 J2EE 应用程序服务器上。 - can contain multiple JAR and WAR files - 可以包含多个 JAR 和 WAR 文件

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).通过隔离类加载器,您的耳朵类加载器将不会在父类(=JBoss / 其他 AS 类加载器)中查找。 As far is I know, this is not possible with war files.据我所知,这对战争文件是不可能的。

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. Java 档案 (JAR)一个 JAR 文件封装了一个或多个 Java 类、一个清单和一个描述符。 JAR files are the lowest level of archive. JAR 文件是最低级别的存档。 JAR files are used in J2EE for packaging EJBs and client-side Java Applications. JAR 文件在 J2EE 中用于打包 EJB 和客户端 Java 应用程序。

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

  3. Enterprise Archives (EAR) ”An EAR file contains all of the components that make up a particular J2EE application. Enterprise Archives (EAR) “EAR 文件包含构成特定 J2EE 应用程序的所有组件。

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. WAR (web archive) - 每个 war 代表一个 web 应用程序 - 只使用 web 相关技术,如 servlet、jsps 可以使用。 - can run on Tomcat server - web app developed by web related technologies only jsp servlet html js - info representation only no transactions. - 可以在 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. EAR(企业档案)——每只耳朵代表一个企业应用——我们可以使用 j2ee 中的任何东西,比如 ejb,jms 可以愉快地使用。 - can run on Glassfish like server not on Tomcat server. - 可以像服务器一样在 Glassfish 上运行,而不是在 Tomcat 服务器上运行。 - enterprise app devloped by any technology anything from j2ee like all web app plus ejbs jms etc. - does transactions with info representation. - 由 j2ee 任何技术开发的企业应用程序,如所有 Web 应用程序以及 ejbs jms 等。 - 使用信息表示进行交易。 eg.例如。 Bank app, Telecom app银行应用、电信应用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM