views:

44

answers:

2

I have a JEE web application that does not make use of EJBs. I am targeting Jetty/Tomcat for deployment some of the time and thus need a WAR packaging. However, I am also target JBoss and Websphere some of the time.

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

+3  A: 

If you have only web modules - use WAR file. If you have different J2EE modules - use EAR. Though you can deliver only web modules in EAR - there is no point in doing this (and you will need to do more complex deployment configuration)

Andriy Sholokh
What are examples of other "J2EE modules"?
HDave
For example, EJB, WebServices
Andriy Sholokh
My application has web services (SOAP), but I am not sure why this would benefit from an EAR...could you elaborate?
HDave
First of all, are you sure that your web services configured to work on Tomcat? If you have couple modules you will need to deploy them as separate WAR files to Tomcat (As Tomcat does not support EARs)Here is benefit of Application Servers like WebSphere and EARs... You can put all your web modules and web services to single deployment file (EAR). And they will be installed all togather.
Andriy Sholokh
I was using 2 servlets within the same WAR. Is there any reason it would better to make them 2 WARs within an EAR?
HDave
I don't see any reason
Andriy Sholokh
A: 

The crucial point is if you need anything provided in an EAR file (which may contain said WAR file). If so, then it makes sense to deploy as an EAR.

It can also wire up some of the configuration you need to do manually in Tomcat etc. A typical example is the URL bound to the web application, where you need to override the default heuristic with a container specific configuration file for a WAR, but you can put it directly in the EAR configuration file.

Also, during development WARs can frequently be hotdeployed directly in exploded form, where EARs must be unpacked and deployed. For Glassfish from Eclipse the difference is quite noticeable.

Thorbjørn Ravn Andersen
I could not find in the Tomcat documentation how one deploys an EAR there. Is this using the Embedded JBoss?
HDave
You cannot deploy EAR's in Tomcat. But you can have a naked WAR and the exact same WAR wrapped nicely in an EAR for separate servers.
Thorbjørn Ravn Andersen
Yes, you can't deploy EARs to Tomcat, because Tomcat is a servlet container not an application server.So, if you need to deploy your web application both to Tomcat and JBoss and WebSphere use WAR file. It will work for all of them
Andriy Sholokh