I am using EJB 3.1 in my application.
I want to send one EJB's JNDI look-up name in my application to another application so that it can use that at run time & communicate with my EJB. As the look-up name depends upon the name of the ear files deployed on the EJB container & the name of these ear files will be changing every time any changes are done in my application.
What is the procedure of finding out the look-up name of the any EJB programmatically.
To view this administrative console page, click Applications > Application Types > WebSphere enterprise applications > application > EJB JNDI names.
JNDI lookup from an application running in a container. Applications that run in a container can use java: lookup names. Lookup names of this form provide a level of indirection such that the lookup name used to look up an object is not dependent on the object's name as it is bound in the name server's namespace.
Thus, accessing the EJB is simple: no JNDI properties are required. //Get the Initial Context for the JNDI lookup for a local EJB InitialContext ic = new InitialContext(); //Retrieve the Home interface using JNDI lookup Object hello Object = ic. lookup("java:comp/env/ ejb/HelloBean ");
First of all, I wouldn't recommend that approach. Why don't you fix JNDI names of your EJBs?
That said, you can call a method InitialContext#list
to iterate through the JNDI tree and find out the name of your EJB. There is a nice code example here, so I won't repeat it. An important note - calling ctx.list("")
will only give you first level of JNDI tree, so you will have to call that method recursively in order to obtain EJB names. Hint: EJBs are usually deployed under branch ejb.
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With