Everything derives from the InitialContext which you use to perform lookups. Check out this code:
Hashtable env = new Hashtable();
Context ctx = new InitialContext( env );
This assumes that you're running the default JBoss naming service on a host known as somehost at the default port (1099). Now you can just use ctx in the usual manner, i.e.:
Object obj = ctx.lookup( "someclass" );
Be sure to use PortableRemoteObject.narrow() rather than just a simple cast as you're dealing with a remote reference here.
Thanks for the reply.
I know the actual JNDI mechanics of doing this, but I was looking for a way to do it outside of the code, e.g. in the deployment descriptor or in the JBoss configuration files. I don't want the code to have to particpate in JNDI management.
Section 19.7 of the spec states that the container must take care of linking an <ejb-ref> to the InitialContext of the owning server, but doesn't say where to specify the server. I'm assuming that the way to do it is container-specific, so basically what I'm asking is how to tell JBoss to do it...
For your ejb-ref tag set in jboss.xml, try:
I haven't tried it in a while but it should work. You then use the ejb-ref in your lookup.
You'll need to create the appropriate ejb-ref tags in ejb-jar.xml to complete the mapping.
This, as with the original suggestion, only works with communication using the same JBoss version servers - due to the requirements of Java class versioning imposed by the client-server communication.
Refer to http://amitysolutions.com.au/documents/JBossTomcatJNDI-technote.pdffor more information on reference mappings.
Hope that helps.
Sounds promising; I'll try it. Thanks for the post.