Binding JNDI Objects

After the initial JNDI context has been obtained, a program can look up existing objects and bind new objects to the context.

When working with EJBs, the main JNDI activity is to look up existing bound objects; the J2EE server does most of the binding of the objects automatically.

Because this section discusses the binding of objects, you can skip it if your primary purpose for using JNDI is to obtain EJB and other references within a J2EE application.

Binding Objects

Binding an object means adding a name to the JNDI service and associating that name with a Java object. The name and object are bound to a context. Listing 3.1 shows how a text message can be bound to the name sams/book.

Listing 3.1. Full Text of JNDIBind.java ...

Get Sams Teach Yourself J2EE™ in 21 Days 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.