Calling an enterprise bean is the process of getting a reference to the enterprise
bean so that you can call its methods. The IDE can assist you when calling an enterprise bean from
any Java class in an EJB module, web application, or enterprise application client.
To call an enterprise bean:
Open the IDE project that contains the enterprise bean that you want to
call.
Open the file from which you want to call the enterprise bean.
In the Source Editor, right-click anywhere in the body of the class and
choose Enterprise Resources > Call
Enterprise Bean.
In the dialog box, select the enterprise bean you want to call.
If the project uses the J2EE 1.4 specification, select whether to
use inline lookup code or use an existing service
locator class.
(Optional) Type a new name for the reference.
Specify whether to reference the local interface or the remote interface.
In order to reference a bean's local interface, the class that is referencing
the bean must be packaged in the same enterprise application as the enterprise
bean.
Click OK.
When you call an enterprise bean, the following occurs:
Java EE 5 projects:
The IDE uses the @EJB annotation to indicate a dependency on another bean.
In the Java class from which you are calling the enterprise bean, the IDE adds code similar to the following:
@EJB
private NewSessionRemote newSessionBean;
The enterprise bean project is added to the caller project's classpath.
J2EE 1.4 projects:
A lookup method is created in the caller class.
The enterprise bean project is added to the caller project's classpath.
A reference to the entity or session bean being called is added to the deployment descriptor of the caller project.
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.