JNDI Basics

The Context class is the core of the JNDI API. You use it to perform any lookup and to add any new name-value associations. When you use JNDI, you typically create an InitialContext object first:

Context ctx = new InitialContext();

The InitialContext constructor looks for a system property called java.naming.factory. initial that contains the name of the class that creates the InitialContext. Sometimes, you must supply this value yourself. Some EJB containers, like the one that comes with Sun's J2EE SDK, already have this property set.

JDK 1.3 comes with three built-in service providers: RMI, CORBA, and LDAP. The classnames for the different initial context factories are

 com.sun.jndi.rmi.registry.RegistryContextFactory com.sun.jndi.cosnaming.CNCtxFactory ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.