Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the JNDI look-up name of EJB programmatically?

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.

like image 480
Sameer Avatar asked Mar 10 '13 17:03

Sameer


People also ask

Where can I find JNDI name?

To view this administrative console page, click Applications > Application Types > WebSphere enterprise applications > application > EJB JNDI names.

What is JNDI lookup in EJB?

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.

How do I access local EJB?

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 ");


1 Answers

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:

  • InitialContext
like image 92
Miljen Mikic Avatar answered Oct 03 '22 03:10

Miljen Mikic