Selecting and Configuring a JNDI Provider

   

As with virtually every other Java technology, JNDI must be properly configured before you can begin to use it. This is mainly due to the separation of interfaces and implementation. The naming service must be properly configured so that an installed provider will handle the work when a client uses the JNDI APIs. Also, any client application that wants to use the naming service must also be properly configured so that it can locate the naming service and then look up resources within it.

Configuring JNDI sometimes can cause great frustration unless you really understand what you are trying to set up and why. When using an EJB server, JNDI is usually already configured for the server and starts up when the EJB server starts up. The only part that you typically need to configure is the client application that is looking for home or remote references. The EJB server typically has an implementation that handles the JNDI service, and you just need to know how to find and connect to it.

To provide you with a little more depth about JNDI and how it is used, we will take you through the steps of setting up your own JNDI naming service and not using the one provided with the EJB server. This should give you a little more insight on what's going on within the EJB server for JNDI and how an SPI really handles the service, not just the JNDI APIs.

Note

To reiterate, if you are using an EJB server, you will typically not have to set up your own JNDI service. The JNDI server configuration is taken care of by most EJB servers. However, you still will need to set up the client applications that need to use JNDI.


The Java SDK 1.3 comes with three different naming service providers already included. The three are

  • LDAP

  • COS Naming

  • RMI Registry

We could select one of these SPIs for our example, but each one is somewhat complicated to set up and understand. We would spend too much time talking about a separate technology that really doesn't have much to do with EJB and JNDI. There are a few extra naming service providers that we can download. You can download the extra SPIs from the following URL:

http://java.sun.com/products/jndi

If you get the JNDI 1.2.1 download, which is separate from the main JNDI download, it provides the following extra SPIs:

  • LDAP v3

  • NIS

  • File System

These extra SPIs are in beta right now, but fine for what we need to do. We are going to be using the file system service provider for our examples. This will allow your file system to act as a JNDI naming service. This works out well for our example, because you already know how to use your computer's file system. You can download the File System (FS Context) naming service provider separately from the rest and install it on your computer. It comes with installation instructions, but the installation mainly involves putting the fscontext.jar and providerutil.jar JAR files from the download into your <JAVA_HOME>/ lib directory. The other nice thing about using this SPI is that there's really no naming service to start. Because your file system is the service, it's already started for you. The other setup procedure that you will need to do is to create a directory on your file system that will act as the root of the naming service. If you are using the Windows platform, it could be something like

 C:\JNDI_ROOT 

For Unix, you might create a directory under your user account like

 /home/chuck/jndi_root 

If you would like to use a different JNDI provider, such as LDAP or WebLogic's naming service, check with the vendor on how to set up and start the service. The examples that will be used in this chapter are designed for the file system service provider, but with little modifications it can work with other providers.

Note

Java SDK 1.3 includes the jndi.jar file, which contains the necessary JNDI APIs. This JAR file must be in your classpath for your JNDI client applications to work. If you have an earlier version of Java, you will need to download the JNDI APIs separately and follow the installation instructions for the particular version of Java that you're using. You can download JNDI from http://java.sun.com/products/jndi.


It should also be said that if you're planning to use a different naming service provider other than the file system provider, you will also need to include the JAR files for that provider in your client classpath or you will get compiler or runtime errors. The client applications that will be accessing JNDI will need to import the necessary JNDI packages. For our discussion of EJB 2.0, the only JNDI package that you will need to import into your client applications is the javax.naming package.

The Example File System Namespace

The nice thing about using the file system SPI for JNDI is that nothing needs to be started for the JNDI naming service. All you need to do is set up a directory to represent the JNDI namespace. For our examples, we will use the directory structure shown in Figure 4.5.

Figure 4.5. The JNDI namespace that will be used for the file system example.

graphics/04fig05.gif

If you would like to use a different drive, or if you are using Linux or Unix as your operating system, then change the names and drive accordingly wherever the namespace is referenced in the examples.



Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net