tags:

views:

1962

answers:

4
+4  Q: 

.war vs .ear file

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

+4  A: 

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

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

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).

paxdiablo
+13  A: 

Check here:

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

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

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

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

elhoim
+3  A: 

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

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.

David Rabinowitz
+3  A: 

WAR (Web Archive) is a module that goes into web container of J2EE/JEE application server. JEE application server has two containers (run time environments) - one is web container and other is EJB container

Web container hosts web applications based on JSP/Servlets API - designed specifically for web request handling - more of request/response distributed computing. Web container requires the web module to be packaged in WAR file that is special JAR file with web.xml file in WEB-INF folder

EJB container hosts enterprise java beans based on EJB API designed to provide extended business functionality such as declarative transactions, declarative method level security and multi protocol support - more of RPC style of distributed computing. EJB container required EJB module to be packaged in JAR file having ejb-jar.xml file in META-INF folder.

Enterprise application may consist of one or more than modules that can either be Web modules (packaged in WAR file) or EJB modules (packaged in JAR file) or both of them. Enterprise applications are packaged in EAR file that is special JAR file containing application.xml file in META-INF folder

Basically EAR file is superset containing WAR file and JAR files. JEE application servers allow deployment of standalong web modules in WAR file though internally they create EAR file as wrapper around WAR files. Standalone web container such as tomcat and jetty donot support EAR files - these are not full fledged application servers. Web applications in these containers are to be deployed as WAR file only.

In application servers - EAR file contains configuration such as application security role mapping, EJB reference mapping and context root url mapping of web modules

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

Rutesh Makhijani