Generic naming service organization has been decpicted in the following figure: A generic naming service
Set of bindings are maintained by the naming service. Names are related by the bindings to the objects. In a naming system, all the objects are named similarly. Naming service is used by the client so that the objects could be located by names.
Many naming services are present among which few of them will
To access various naming or directory services, JNDI or Java Naming and directory interface is used that is basically an application programming interface (API). Java Naming and directory interfacen is not considered specified to some specific naming/directory service. Various system could be accessed by it which include file systems; Java RMI, EJB, distributed object system & directory services for example NIS+, Novell NetWare and LDAP.
JNDI and JDBC are same because both of
Java Naming & Directory Interface gives the generic interface to the Lightweight Directory Access protocol or other director services for example, DNS or NDS. The components of the J2EE application use JNDI interfaces to look up & to refer the user defined and system provided objects in component environment. JNDI is not defined for one specified directory or naming service. Different system kinds may be accessed which also includes the file systems. The JNDI API makes the applications look
In the post, I will write about how to accessing a bean in EJB.
Accessing deployed beans is simple. First write the the client code and set up JNDI environment settings for the client. It can be done via a JNDI properties file. Now you have to set the class path for the client and add the following file locations to it:
jboss-client.jar, jnp-client.jar, EJB interfaces, and the directory where the JNDI properties file is stored
Remember, two JNDI settings
JNDI is a standard Java API that comes with JDK 1.3 and higher. It provides a common interface to a variety of existing naming services for example DNS, LDAP, Active Directory, RMI registry, COS registry, NIS, and file systems.
The JNDI API is divided logically into a client API and service provider interface. Client API is used to access naming services and a SPI allows the user to create JNDI implementations for naming services.
The naming service providers must implement
JNDI API package is called javax.naming package. It is composed of 5 interfaces, 10 classes along with few exceptions. InitialContext is the key class.
This is what Sun Java Docs say about InitialContext: Java 2 Platform SE v1.3.1: Package javax.naming
In JNDI, all naming and directory operations are performed relative to a context. There are no absolute roots. Therefore JNDI defines an initial context, InitialContext, which provides a starting point for naming