Setting up JNDI for the Java examples

DataSources work hand-in-hand with the Java™ Naming and Directory Interface (JNDI). JNDI is a Java abstraction layer for directory services just as Java Database Connectivity (JDBC) is an abstraction layer for databases.

JNDI is used most often with the Lightweight Directory Access Protocol (LDAP), but it may also be used with the CORBA Object Services (COS), the Java Remote Method Invocation (RMI) registry, or the underlying file system. This varied use is accomplished by means of the various directory service providers that turn common JNDI requests into specific directory service requests.

Note: Keep in mind that using RMI can be a complex undertaking. Before you choose RMI as a solution, be sure that you understand the ramifications of doing so. A good place to begin assessing RMI is Java Remote Method Invocation (RMI) HomeLink outside Information Center.

The DataSource samples were designed using the JNDI file system service provider. If you want to run the examples provided, there must be a JNDI service provider in place.

Follow these directions to set up the environment for the file system service provider:

  1. Download the file system JNDI support from Sun Microsystems JNDI siteLink outside Information Center.
  2. Transfer (using FTP or another mechanism) fscontext.jar and providerutil.jar to your system and put them in /QIBM/UserData/Java400/ext. This is the extensions directory and the JAR files that you place here are found automatically when you run your application (that is, you do not need them in your classpath).

Once you have support for a service provider for JNDI, you must set up the context information for your applications. This can be accomplished by putting the required information in a file. There are several places on the system where you can specify default properties, but the best way is to create a text file called in your home directory (that is, at /home/).

To create a file, use the following lines or add them to your existing file:

# Needed env settings for JNDI.

These lines specify that the file system service provider handles JNDI requests and that /DataSources/jdbc is the root for tasks that use JNDI. You can change this location, but the directory that you specify must exist. The location that you specify is where the example DataSources are bound and deployed.