what is the advantage of using ejb-ref in the web.xml in the .war file? will app server load all referred EJB while loading the web application?
I believe i can call any EJB from my web app thro' JNDI.
Then what does matter providing the ejb-ref in the web.xml ?
The advantage is indirection. Coding direct references to EJB's in your servlets through JNDI will work provided the beans JNDI name does not change during deployment.
By using an ejb-ref you create an alias for the bean. During coding this alias is used to locate the beans home.
The developer also creates an entry in the web.xml like this:
On deployment the deployer creates a mapping between the alias ejb/myBean and the JNDI name the bean is actually deployed with. Mapping is vendor specific feature. For example, in WebLogic this is done in the weblogic.xml file.
Why do it this way? Becuse it allows the deployer to change a beans JNDI name without recompiling the servlet (or having the source code).