Accessing an EJB from a Java Application using JNDI

It would be nice if we could use dependency injection outside of a server container. However, this is not possible from a Java SE application unless we use an embeddable container. Using an embeddable container is covered in the next recipe. Here we need to use JNDI. Accessing an EJB from a Java SE application using JNDI is similar to using JNDI in other types of applications.

Getting ready

To use this approach we need:

  1. A supporting EJB
  2. JNDI code to obtain a reference to the EJB

    We will be using the CapitalApplication developed in the Accessing an EJB from an Applet recipe found in this chapter. This recipe uses a CapitalBean to return the name of the capital given a state. Make sure the server ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.