WAR vs EAR for web applications without EJB?

I have a Java EE web application that does not use EJB. I have been using Jetty / Tomcat for deployment for a while and therefore you need WAR packaging. However, I am also the target of JBoss and Websphere for a while.

I understand that full-blown Java EE application servers can accept EAR or WAR formats. When will I use one over the other and why? I understand that they are both standard compressed file formats, and I read 10 different snippets that try to explain them ( including this one ), but no closer to understanding the pros and cons of each.

+6
java web-applications servlets deployment
source share
3 answers

If you only have web modules, use the WAR file. If you have different Java EE modules, use EAR. Although you can only deliver web modules to the EAR, there is no point in doing this (and you will need to complete a more complex deployment configuration)

+5
source share

The crucial point is that you need something in the EAR file (which may contain the specified WAR file). If so, then it makes sense to deploy as an EAR.

It can also connect some settings that need to be done manually in Tomcat, etc. A typical example is a web application-bound URL where you need to override the default heuristic with a specific configuration file for the WAR, but you can put it directly into the EAR configuration file.

In addition, during development, WARs can often be hotdeployed directly in disassembled form, where EARs must be unpacked and deployed. For Eclipse Glassfish, the difference is quite noticeable.

0
source share

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

If you use only Servlet, JSP, GIF, and HTML files. Then use .WAR

WAR:(Web ARchive) 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. 

If you use different EAV JAVA modules, such as (EJB + Servlet, JSP, GIF and HTML files + other technologies). Then use .EAR

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

All Articles