As per the SCBCD book and Also Mastering
EJB..
The <ejb-ref> tag is used by the Bean Provider to indicate a psuedo name to the assembler, that he is referring to a EJB in his code. And then it is the responsibilty if the App Assembler to map that psuedo name to the actual EJB's jndi name on the container.
Also by using the <ejb-ref> tag, the developer can directly use the following code..
Context c = new InitialContext();
Here in the InitialContext() the developer need not pass any parameter to specify the jdni factory and server name.
This way the code becomes deployable to any container as no specific env. values are passed in the InitialContext().
Now the question is --
Consider the scenario, i have a Address EJB deployed on a container on machine A. And there is another EJB Customer referring to Address, this Customer EJB is deployed in a container on machine B.
In the code of Customer the developer has used --
Context c = new InitialContext();
for accessing the Address EJB.
And he has specified an <ejb-ref> element for the Customer EJB.
Bean devloper is not passing any info to InitialContext(), and also in the ejb-jar.xml file, for the <ejb-ref> of Customer we do not have any tag which says on which machine the Address EJB is deployed.
Also during deployment the deployer only gives maps the psuedo name of <ejb-ref> to the JNDI name of the referenced EJB. He also not specifies the machine name and address.
So how this <ejb-ref> works, when we have to ejb's deployed on two diffrent machines and One want to use the other?
I hope all the above explanation makes sense, even if not, please help me in knowing the <ejb-ref> element better.