.war vs .ear文件

本文详细介绍了.war和.ear文件在Java EE应用中的作用和区别。.war文件用于部署Web应用程序,包含Servlet、JSP、HTML等资源,而.ear文件则用于部署包含EJB、Web应用和第三方库的企业应用,是.war和.jar文件的集合。.ear文件提供更高级别的配置,以实现与应用服务器的交互,避免类加载冲突。

本文翻译自:.war vs .ear file

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


#1楼

参考:https://stackoom.com/question/6gqR/war-vs-ear文件


#2楼

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). 这些文件中可能还有其他内容,但它们基本上意味着它们的含义:对于Web类型的东西的WAR,对于企业类型的东西的EAR(WAR,代码,连接器等)。


#3楼

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 extenstion 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 JAR file with .war (web archive) extension WAR:包含Servlet类文件,JSP文件,支持文件,GIF和HTML文件的Web模块打包为带有.war(web archive)扩展名的JAR文件

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


#4楼

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,类)以及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应用程序和第三方库的企业应用程序。 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文件。


#5楼

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 Application Server有两个容器(运行时环境) - 一个是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容器需要打包为一个WAR文件的Web模块-这是一个特殊的JAR文件web.xml在文件WEB-INF文件夹中。

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文件 - 这些是包含META-INF文件夹中的application.xml文件的特殊JAR文件。

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文件的客户端模块。


#6楼

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. 据我所知,战争档案是不可能的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值