File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes How to modify the JNDI names? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to modify the JNDI names?" Watch "How to modify the JNDI names?" New topic
Author

How to modify the JNDI names?

K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi,

I am using Eclipse+WAS 7 to develop my application. I have an EAR, which has a web application module and an EJB module.
I am able to access my EJB methods using the below client code. This code is from my web application.

My Client to access EJB methods:


Local interface:

Remote interface:

EJB Bean:


I learned that I am accessing the default JNDI name of the EJB.
Could someone please let me know how/where I can customize the JNDI names to access the EJB bean methods so that I can access the bean methods using
ctx.lookup("xx/yyl"); instead of ctx.lookup("ejblocal:a.b.ie.StateLessBeanLocal");

Regards,
Kiran.
Kevin Sheng
Greenhorn

Joined: Jun 26, 2012
Posts: 13
You can put the default name ejblocal:a.b.ie.StateLessBeanLocal to a property file and refer the service as a shorter name like xx.yyl.

In case your ejb changes, just update the property file without changing the code.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Try this for your stateless bean:



You should then be able to lookup your bean using "foo".

Note, a downside to this is that it makes your code less portable.

http://docs.oracle.com/javaee/6/api/javax/ejb/Stateless.html
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi Kevin - Thank you for the response. However, I am looking for the name change as James Suggested.

James - Thanks a lot for your response. I tried out your suggestion. However, I get NameNotFoundException.
I used
StateLessBeanLocal local = (StateLessBeanLocal) ctx.lookup("foo"); in my client code and
@Stateless(name = "foo", mappedName="foo") in my Bean class

Please let me know if I am missing anything here.

Regards,
Kiran.

K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi,

I found the solution. Search for the file ibm-ejb-jar-bnd.xml (should be in ejbModule/META-INF/). Keep an entry in the file.
Example:
<session name="xxxServiceClass" simple-binding-name="ejb/abcd">
<resource-ref name="datasources" binding-name="datasource JNDI name"/> <! This is not mandatory-->
</session>

Regards,
Kiran.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to modify the JNDI names?
 
Similar Threads
Weblogic 9.1 JNDI problem
EJB3 JNDI lookup in WAS7
What is the main method client code for loacl interface in EJB?
JNDI Context
Deploy EJB on J2EE