Calling an enterprise bean is the process of getting a reference to the enterprise
bean so that you can call its methods. In order to call an enterprise bean's methods,
you need to create an instance of the bean's local or remote interface, then call
methods of the interface.
You can automatically generate lookup code for an enterprise bean, including any
deployment descriptor configuration code, by right-clicking a Java file and choosing
Enterprise Resources > Call Enterprise Bean. See
Calling an Enterprise Bean for more information.
The process of calling an enterprise bean differs for Java EE 5 applications
and J2EE 1.4 applications.
Java EE 5 Specification. You use the @EJB annotation to inject
an interface tag. You therefore only have to declare the remote or local interface
by using code similar to the following:
@EJB
private MyEJBInterface newMyEJB;
If you are calling an enterprise bean in a different project, you also
have to add the EJB project to the classpath of the project that is
calling the enterprise bean.
J2EE 1.4 Specification. You use JNDI lookup to locate the bean and retrieve
an instance of the local or remote interface. Each enterprise bean is given a unique
JNDI name in its deployment descriptor. You use a lookup method similar to the following
to locate the enterprise bean:
Finally, you register the EJB reference in the deployment descriptor of the module
from which you are calling the enterprise bean. If and where the reference
is added depends on which of the following applies:
If the lookup is made from an enterprise bean implementation class,
the reference is added to the corresponding bean.
If the lookup is made from any class of a web application,
the reference is added to the web application.
If the lookup is made from a plain Java class of an EJB module,
no reference is added. In this case, the reference has to be added manually
to the bean calling the plain Java class.
Notes:
If you are calling an enterprise bean that is in a and you get an error that the selected bean is not specified in
the distribution archive, you have to specify the EJB module project's output.
Right-click the EJB module's project node, choose Properties, and specify
the output JAR file in the Output panel.
The IDE cannot assist you when calling an enterprise bean from a free-form
web application project.
You can only call an enterprise bean from a free-form EJB module project
if the enterprise bean is located in the same project.