JNDI

Hi,

Can anyone tell me the concept of JNDI in idiot please? What are the differences between naming services and directory services in JNDI itself?

On scenario.
Last time, I was developing J2EE Web Application. I have DataSource on my Tomcat and I bind it in the context. Then my EJB is also bound into JNDI for each of the session bean (Is it? I forgot about it :D). My questions are are these things (DataSource and EJB JNDI) are living together in one place (JNDI)? What would happen if the names are accidentally same? How does JNDI detect it?

Can my J2SE app call JNDI? I believe not but to download dbcp.

Thanks you.

Regards
Dave
LVL 16
suprapto45Asked:
Who is Participating?
 
aozarovCommented:
>> and I am quite confused in are these things (DataSource and EJB JNDI) are living together in one place (JNDI)?
They are not.
Think of jndi as a repository of links of where to find the other J2EE services. (like yellow pages).
It does not really store the EJB but rather store a proxy to the EJB home.
It does not really store the connection pool but rather store the proxy to the data source that is connected to the pool.
You can create your own rmi service and bind your stub (your rmi service proxy) to the jndi with a specific name.

>> What does it mean? Can you explain more?
If you look at the Directory API http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html you will see
that it extends Context (the standard naming service api) and add to it method to get attributes that were associated with
the object that was bound under that name.
0
 
aozarovCommented:
>> concept of JNDI
A lookup service based on key to identify the request and a value (stored object)

>> What are the differences between naming services and directory services in JNDI itself?
directory services provides attributes on their stored objects.

see: http://java.sun.com/products/jndi/tutorial/

>> What would happen if the names are accidentally same?
If you bind something with a name that already exists you will get an exeption unless you called rebind instead of bind.

>> Can my J2SE app call JNDI?
Sure, why not (it is part of the j2se sdk since 1.4), you just need a naming service running.
0
 
aozarovCommented:
Some addon:

>> directory services provides attributes on their stored objects.
To make it clear, Directory serice is an extension of a naming service.

>> If you bind something with a name that already exists you will get an exeption unless you called rebind instead of bind.
And in the tomcat case, probably bind and not rebind is called, so you will get NamingException if that happens.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
suprapto45Author Commented:
Hi aozarov,

"directory services provides attributes on their stored objects."

What does it mean? Can you explain more?

and I am quite confused in are these things (DataSource and EJB JNDI) are living together in one place (JNDI)?

Regards
Dave

0
 
suprapto45Author Commented:
mmm...thanks.

will Context make any difference in storing JNDI? Since if I am not mistaken, if I want to create DataSource in Tomcat, I need to set it in Context.

Regards
Dave
0
 
aozarovCommented:
>> I need to set it in Context
This just happened to have the same name :-))
The context you are talking about is Tomcat way of defining a web application -> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html
and this linke explains how to add to it the datasource http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
0
 
aozarovCommented:
The link I gave you above is one of the most complete tutorials available on JNDI
But if you are looking for a good and quick tutorial then you can have a look at:
http://www.javaworld.com/javaworld/jw-01-2000/jw-01-howto_p.html
0
 
suprapto45Author Commented:
Thanks aozarov.

Regards
Dave
0
 
aozarovCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.