Sun GlassFish Enterprise Server v3 Administration Guide

About JNDI

By making calls to the JNDI API, applications locate resources and other program objects. A resource is a program object that provides connections to systems, such as database servers and messaging systems. A JDBC resource is sometimes referred to as a data source. Each resource object is identified by a unique, people-friendly name, called the JNDI name. A resource object and its JNDI name are bound together by the naming and directory service, which is included with the Enterprise Server.

When a new name-object binding is entered into the JNDI, a new resource is created.

The following topics are addressed here:

J2EE Naming Environment

JNDI names are bound to their objects by the naming and directory service that is provided by a J2EE server. Because J2EE components access this service through the JNDI API, the object usually uses its JNDI name. For example, the JNDI name of the PointBase database is jdbc/Pointbase. At startup, the Enterprise Server reads information from the configuration file and automatically adds JNDI database names to the name space, one of which is jdbc/Pointbase.

Java EE application clients, enterprise beans, and web components must have access to a JNDI naming environment.

The application component's naming environment is the mechanism that allows customization of the application component's business logic during deployment or assembly. This environment allows you to customize the application component without needing to access or change the source code off the component. A Java EE container implements the provides the environment to the application component instance as a JNDI naming context.

How the Naming Environment and the Container Work Together

The application component's environment is used as follows:

Each application component defines its own set of environment entries. All instances of an application component within the same container share the same environment entries. Application component instances are not allowed to modify the environment at runtime.

Naming References and Binding Information

A resource reference is an element in a deployment descriptor that identifies the component’s coded name for the resource. For example, jdbc/SavingsAccountDB. More specifically, the coded name references a connection factory for the resource.

The JNDI name of a resource and the resource reference name are not the same. This approach to naming requires that you map the two names before deployment, but it also decouples components from resources. Because of this decoupling, if at a later time the component needs to access a different resource, the name does not need to change. This flexibility makes it easier for you to assemble J2EE applications from preexisting components.

The following table lists JNDI lookups and their associated resource references for the J2EE resources used by the Enterprise Server.

Table 20–1 JNDI Lookup Names and Their Associated References

JNDI Lookup Name 

Associated Resource Reference 


Application environment entries 


JDBC DataSource resource manager connection factories 


EJB References 


UserTransaction references 


JavaMail Session Connection Factories 


URL Connection Factories 


JMS Connection Factories and Destinations 


ORB instance shared across application components