Obtain the initial JNDI context for the component

To access an enterprise resource such as a data source or JavaMail session in a distributed computing environment, you can use the JNDI API to locate that object so that you can use it in your code. To do this, you must first obtain the initial context that contains the resource (a Java object).

You can obtain an initial JNDI context in one of two ways:

Get an initial context using JNDI properties found in the current environment

The current environment includes the Java system properties and properties defined in properties files found in the classpath. This code snippet illustrates how to obtain the initial context from these properties:

import javax.naming.Context;
import javax.naming.InitialContext;

// ... class declaration, method declaration code here ...

Context initialContext = new InitialContext();

Get an initial context by explicitly setting JNDI properties

In general, JNDI clients should assume that the correct environment is already configured. If this is the case, there is no need for you to explicitly set property values and pass them to the constructor of the InitialContext object. However, a JNDI client might need to access a namespace other than the one identified in its environment. In this event, you must explicitly set one or more properties used by the InitialContext constructor. Any property values you pass to the InitialContext constructor take precedence over settings of the equivalent properties found elsewhere in the client's environment.

You can use two different provider URL forms with WebSphere Application Server's initial context factory:

CORBA object URLs are more flexible than IIOP URLs and are the recommended URL format to use. CORBA object URLs are part of the OMG CosNaming Interoperable Naming Specification. A corbaname URL, for example, can include initial context and lookup name information and can be used as a lookup name without the need to explicitly obtain another initial context.The IIOP URLs are the legacy JNDI format, but are still supported by the WebSphere Application Server initial context factory.