Summary
JNDI provides a uniform API to an underlying naming or directory service. A Naming Service provides a means of storing simple information against a name so the information can be retrieved using the name as a key. A Directory Service stores additional attribute information against a name. Directory Services use attributes to categorize names so that powerful searching of the directory tree structure can be supported.
JNDI supports any naming service provided a Service Provider implementation is available for that service. Standard services supported by JNDI include the following:
Lightweight Directory Access Protocol (LDAP)
Novell Directory Services (NDS)
CORBA
Active Directory is supported via its LDAP interface
Using JNDI from within a Java program is a simple matter of creating a context and looking up names within that context. The Context class supports naming services, and the DirContext class supports directory services.
After a context has been defined, the lookup() method is used to retrieve the object stored against a name. The bind() and rebind() methods are used to add or changes bound objects, and the unbind() method is used to remove a bound object.
Within J2EE, JNDI is used to advertise components such as the following:
EJBs
Datasources (databases)
Resource adapters
JMS message queues and topics