lovespring
lovespring

Reputation: 19559

About Java EE deployment style, which is better?

I have a project, b/s architecture. and with EJB.

So, I can deploy it in two package: a war, and a ejb-jar.

and also, I could deploy it in ONE package: a EAR.

what's the advantage of deploy those two package to ONE ear ?

Upvotes: 0

Views: 58

Answers (2)

Gas
Gas

Reputation: 18020

Just my 2 cents to discussion here. If there is dependency between modules (e.g. war components are calling EJBs) I'd vote for single ear deployment, because:

  • easier management (single install/uninstall, start/stop) and a bit more logical (if you stop just ejb-jar, your web module wont work anyway.
  • can share some classes via util jars in ear/lib folder instead of duplication in each module or creating external shared lib
  • can use local interfaces and auto binding of @EJB references

Two separate modules would be better, if:

  • ejb-jar is shared by many independent applications (web modules) (kind of shared, service layer)
  • you would like to update web module without affecting ejb module.

Upvotes: 0

SubOptimal
SubOptimal

Reputation: 22973

For me the following quotation (taken from the book "JBoss at work") explains it very well:

 An EAR is like a carton of eggs—it keeps everything organized. While the carton doesn’t
 add any direct value to your omelet, it makes getting the eggs home from the store so
 easy that you wouldn’t think about transporting eggs any other way.
 Each egg in your EAR carton is a specific piece of the J2EE puzzle (WAR, EJB, JAR).

edit as suggested by @DavidWallace find a refined answer below...

There is no such thing as an "advantage" of an EAR.

PRO: You can put everthing thing you need to deploy into a single archive.
CON: If you include a vendor specific deployment descriptor (for easy deployment) you might need to repackage the EAR if you want to deploy it into an application server from a different vendor.

At the end it's only a matter of assembling/packaging if you use an EAR or separate modules. Independent from that there is no extra coding needed.

Upvotes: 3

Related Questions