Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes BEA/Weblogic and the fly likes JNDI Name format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "JNDI Name format" Watch "JNDI Name format" New topic
Author

JNDI Name format

Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
All,
I tried to assign the JNDI name for my EJBs using the format below:
java:comp/env/ejb/[bean name]
Example: java:comp/env/ejb/DummyBeanRemote.
During the server startup, I get the exception below:
[javax.management.MalformedObjectNameException: ObjectName: Invalid
value -> java:comp/env/ejb/DummyBeanRemote]
Am I using the right format? What is the correct format for JNDI name other than simple name like "DummyBeanRemote"? Thanks.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
You need to assign the JNDI name in the weblogic-ejb-jar.xml file

Refer some examples for this.
Now assigning the name "java:comp/env/ejb/[bean name]"
Would mean that the name to be looked up will be
java:comp/env/java:comp/env/ejb/[bean name] since the JNDI look up starts at java:comp/env
So you need to use a simple name this like ejb/name
I hope u get the picture
I also think that the error message you are getting is because perhaps the ":" in java:comp/env/ejb/[bean name] which causes the JNDI lookup to be java:comp/env/java:comp/env/ejb/[bean name] is not a valid name
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Originally posted by Rahul Mahindrakar:

Now assigning the name "java:comp/env/ejb/[bean name]"
Would mean that the name to be looked up will be
java:comp/env/java:comp/env/ejb/[bean name] since the JNDI look up starts at java:comp/env

Alright. I tried two things.
I named all my beans with the format "ejb/[bean name]" in weblogic-jar.xml
1)Then I tried to lookup the tree using the format "java:comp/env/ejb/[bean name]". It didn't work for both EJBs and Data Source.
2)I tried to lookup the tree using the format "ejb/[bean name]". Now I can find and use the EJB and Data Source.
I can live with this approach. But I am trying to understand the context "java:comp/env". If you take a look at the link below, the J2EE blueprint code indeed looks up the JNDI tree for EJBs using the format "java:comp/env/ejb/[bean name]". How come that works?
com.sun.estore.util.JNDINames
[ March 13, 2003: Message edited by: Sai Prasad ]
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2849
    
  11

I think you may be getting confused by resource references. An EJB descriptor in ejb-jar.xml can contain a <resource-ref> clause that refers to another resource like a DataSource, JMS Connection Factory, Mail Session, or even another related EJB. There is a related clause, <reference-descriptor>, in the weblogic-ejb-jar.xml, which maps the resource reference name to the true JNDI name of the resource.
Now, if all that's in place, then within the EJB code, you can look up a resource by its resource reference name, instead of its true JNDI name. However, you prepend java:/comp/env/ to the resource reference name that appears in the descriptor. This indirection allows you to change what resources an EJB employs without having to recode the bean. You just have to modify the deployment descriptors.
Is that clear? I know it took me a long time to understand. The bottom line is the JNDI name for your EJBs should be the same as the remote interface name (by tradition) or could be ejb/[remote interface name]. Your clients retrieve the EJB by that same name, unless possibly when the client is another EJB.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Hi,
I got your problem. Here is the relevant section as per the J2EE 1.3 spec
• This specification recommends, but does not require, that all references to enterprise
beans be organized in the ejb subcontext of the application component’s
environment (that is, in the java:comp/env/ejb JNDI context).

Working on it
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Here is one more post
http://www.coderanch.com/t/307957/EJB-JEE/java/Moving-application-iPlanet-WebLogic
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1850
Hi
I too had this problem many a times wherein I could never use java:comp/env from a client for a ejb lookup. The lookup has always been something like ejb/ejbName. Weblogic somehow hides the earlier string even in the console.
However I would be very much intrested to know how a bean that is J2EE complient would be deployed successfully in a Weblogic server without this change of lookup name.
For example a client would look up normally like this
java:comp/env/ejb/ejbName
But this would not work in Weblogic for some reason and the JNDI lookup below is needed
ejb/ejbName
so the Client code is not portable accross application servers.
Will investigate further
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI Name format