Using the lookup Method to Locate JNDI Resources

Now that you’ve learned how to get the InitialContext, it’s time to do something with it. That something is to look up objects and references to objects. Because we are using the file system service provider, the object that we will be using to look up will be a text file.

Create a text file called foobar.txt and save the file into your jndi_root directory. You can add some text to the file if you want; it doesn’t matter for our example. Now, let’s use JNDI to look up this file and print out some information about it. Listing 4.6 shows a program that creates an InitialContext on our JNDI root directory and then performs a lookup on a name. The name is the name of the file foobar.txt.

Listing 4.6. ...

Get Special Edition Using Enterprise JavaBeans™ 2.0 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.