Java Naming and Directory Interface
Encyclopedia
The Java Naming and Directory Interface (JNDI) is a Java API
for a directory service
that allows Java software clients to discover and look up data and objects via a name. Like all Java
APIs that interface with host systems, JNDI is independent of the underlying implementation. Additionally, it specifies a service provider interface
(SPI) that allows directory service
implementations to be plugged into the framework. It may make use of a server, a flat file, or a database; the choice is up to the vendor.
and Java EE APIs to look up objects in a network. Jini
has its own lookup service and does not use the JNDI API.
The API provides:
The SPI
portion allows support for practically any kind of naming or directory service including:
The JNDI specification was first released by Sun Microsystems
on March 10, 1997.http://www.sun.com/smi/Press/sunflash/1997-03/sunflash.970310.10204.html , the current version is JNDI 1.2.
The JNDI API defines a context that specifies where to look for an object. The initial context is typically used as a starting point.
In the simplest case, an initial context must be created using the specific implementation and extra parameters required by the implementation. The initial context will be used to look up a name. The initial context is analogous to the root or top of a directory tree for a file system. Below is an example of creating an initial context:
A context is then used to look up previously bound names in that context. For example:
Alternative to above code is as below:
The Context object can also be configured by adding jndi.properties file in classpath containing initial context factory class name and provider URL. The above code will be reduced as shown below:
A context is then used to look up previously bound names in that context. For example:
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
for a directory service
Directory service
A directory service is the software system that stores, organizes and provides access to information in a directory. In software engineering, a directory is a map between names and values. It allows the lookup of values given a name, similar to a dictionary...
that allows Java software clients to discover and look up data and objects via a name. Like all Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
APIs that interface with host systems, JNDI is independent of the underlying implementation. Additionally, it specifies a service provider interface
Service provider interface
Service Provider Interface is a software mechanism to support replaceable components.It is the implementer-side equivalent of an API; a set of hooks that can or must be overridden....
(SPI) that allows directory service
Directory service
A directory service is the software system that stores, organizes and provides access to information in a directory. In software engineering, a directory is a map between names and values. It allows the lookup of values given a name, similar to a dictionary...
implementations to be plugged into the framework. It may make use of a server, a flat file, or a database; the choice is up to the vendor.
Background
The JNDI API is used by the Java RMIJava remote method invocation
The Java Remote Method Invocation Application Programming Interface , or Java RMI, is a Java application programming interface that performs the object-oriented equivalent of remote procedure calls ....
and Java EE APIs to look up objects in a network. Jini
Jini
Jini , also called Apache River, is a network architecture for the construction of distributed systems in the form of modular co-operating services.Originally developed by Sun, Jini was released under an open source license...
has its own lookup service and does not use the JNDI API.
The API provides:
- a mechanism to bind an object to a name
- a directory lookup interface that allows general queries
- an event interface that allows clients to determine when directory entries have been modified
- LDAP extensions to support the additional capabilities of an LDAP service
The SPI
Service provider interface
Service Provider Interface is a software mechanism to support replaceable components.It is the implementer-side equivalent of an API; a set of hooks that can or must be overridden....
portion allows support for practically any kind of naming or directory service including:
- LDAPLightweight Directory Access ProtocolThe Lightweight Directory Access Protocol is an application protocol for accessing and maintaining distributed directory information services over an Internet Protocol network...
- DNSDomain name systemThe Domain Name System is a hierarchical distributed naming system for computers, services, or any resource connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities...
- NISNetwork Information ServiceThe Network Information Service, or NIS is a client–server directory service protocol for distributing system configuration data such as user and host names between computers on a computer network...
- CORBAÇorbaChorba , ciorbă , shurpa , shorpo , or sorpa is one of various kinds of soup or stew found in national cuisines across Middle East...
name service - File systemFile systemA file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...
The JNDI specification was first released by Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...
on March 10, 1997.http://www.sun.com/smi/Press/sunflash/1997-03/sunflash.970310.10204.html , the current version is JNDI 1.2.
Basic lookup
JNDI (Java Naming and Directory Interface) organizes its names into a hierarchy. A name can be any string such as "com.mydomain.ejb.MyBean". A name can also be an object that supports theName
interface, however a string is the most common way to name an object. A name is bound to an object in the directory by storing either the object or a reference to the object in the directory service identified by the name.The JNDI API defines a context that specifies where to look for an object. The initial context is typically used as a starting point.
In the simplest case, an initial context must be created using the specific implementation and extra parameters required by the implementation. The initial context will be used to look up a name. The initial context is analogous to the root or top of a directory tree for a file system. Below is an example of creating an initial context:
A context is then used to look up previously bound names in that context. For example:
Alternative to above code is as below:
The Context object can also be configured by adding jndi.properties file in classpath containing initial context factory class name and provider URL. The above code will be reduced as shown below:
A context is then used to look up previously bound names in that context. For example: