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

1

6

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.

Caesar answered 10/3, 2013 at 17:20 Comment(0)
C
6

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:

Countertenor answered 11/3, 2013 at 11:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.