I am trying to access an EJB on server1 from an EJB on server2 (each server is running on its own PC). I first packaged the entire application (war and ejb-jar files) in one ear file and deployed it to server1, and verified that I could access the EJB from my web application. I then deployed the same ear to server2 and verified that once again I could access the EJB on server2 from the web app on server2. So far so good.
I then changed the JNDI lookup on server2 such that it used the URL jnp://server1:1099 for the initial context. Then, using the web app on server2, I attempted to access the EJB and I got the EJB from server2, not from server1.
I did a little digging and found the culprit to be the ejb-ref nodes in web.xml and jboss-web.xml. Once I commented them out, I could then use the web app on server2 to access the EJB on server1. (My code that looks up the EJB by name first tries the name ?java:comp/env/XXX?, and if that fails, tries just ?XXX?.)
After thinking about this for a minute, the above behavior (before I changed web.xml and jboss-web.xml) doesn?t make sense. After all, in my code that runs on server2 I get an initial context supposedly based on the JNDI tree for server1, yet when I ask for an object with a given name, I get an object from the JNDI tree in server2. Is this a bug? Should I open a JIRA? Or am I just clueless?