What is the difference between a .war and .ear file?
WAR (Web Archive) is a module that goes into web container of Java EE application server. A Java EE application server has two containers (run time environments) - one is a web container and the other is a EJB container
The 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 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. Java EE application servers allow deployment of standalone 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
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.
WAR (web archive) files contain servlet class files, JSPs (Java servlet pages), HTML and graphical files, and other supporting files.
EAR (enterprise archive) 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).
tar (tape archives) - Format used is file written in serial units of fileName, fileSize, fileData - no compression. can be huge
Jar (java archive) - compression techniques used - generally contains java information like class/java files. 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
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
Ear files provide more options to configure the interaction with the application server.
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:
or to src/main/application/META-INF/jboss-app.xml :
This will make sure that there is no classloader conflict between your application and the application server.
Normally the classloader mechanism works like this:
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.
protected by Gilbert Le Blanc May 10 '13 at 17:01
Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?