my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes What's the point of an ear file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "What Watch "What New topic
Author

What's the point of an ear file?

Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
Can someone please explain to me what advantages are provided with the creation of a .ear file as opposed to a .war or an ejb.jar? Thank you.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Ears are a standardized way of packaging and deploying applications that make use of J2EE components. It allows one to keep all of the ejb-jars and wars together as a cohesive unit and goes to some length to define how classes are shared among the components, though the specification still needs work here as anyone who has had to deal with J2EE Classloading pains can attest.
Using ears are much easier than separately deploying and configuring multiple J2EE components and dealing with the even greater class sharing headaches that result from this.
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
A coworker of mine created a .ear file with some servlets and ejbs inside it. I have created my own .war files that use ejbs from the .ear file. Is this a strange configuration? Should I instead create a .ear of my own and put his ejb.jar file inside it?
Recently, my coworker did a hot deploy of his .ear file on JBoss and the servets in my .war file could no longer get valid references to the ejbs in the .ear. However, my coworker's servlets worked fine with the ejbs since they were placed inside the same .ear. Should I change the way I am using his ejbs? If so, how? Thanks.
Srikanth Shenoy
author
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
Originally posted by Anthony Watson:
A coworker of mine created a .ear file with some servlets and ejbs inside it. I have created my own .war files that use ejbs from the .ear file. Is this a strange configuration? Should I instead create a .ear of my own and put his ejb.jar file inside it?
Recently, my coworker did a hot deploy of his .ear file on JBoss and the servets in my .war file could no longer get valid references to the ejbs in the .ear. However, my coworker's servlets worked fine with the ejbs since they were placed inside the same .ear. Should I change the way I am using his ejbs? If so, how? Thanks.

Anthony,
Your packaging is wrong.
Your coworker can access the ejbs from his servlets because they reside in the same ear (and hence they have a class loader hierarchy. One is visible to the other)
In your case, you are trying to access the ejbs in his/her ear. For that to work, you need to bundle just the remote and home interfaces of those EJBs in your WAR.
I could go on and on about how to package J2EE classes and dozens of deployment considerations and impact of classloader hierarchy on deployment, but I strongly suggest you should read the sample chapters from "J2EE Project Survival Guide" - a book that I am currently authorng. I bet all your questions regarding classloading and deployment will be answered. The beta chapters are available for free at ServerSide:
Free Chapters on J2EE Classloading and deployment
Srikanth Shenoy
Author: Struts Survival Guide
 
 
subject: What's the point of an ear file?