EJB functionality that is supported
for beans packaged inside EJB JAR modules is also supported for beans
packaged inside WAR modules. A bean packaged inside a WAR module is
capable of the same behavior as a bean packaged inside an EJB JAR
module.
Before you begin
You must have a web project created in your workspace.
About this task
You can now place EJB classes directly in the .WAR file, using the same packaging
guidelines that apply to web application classes. You can place EJB classes under the
WEB-INF/classes directory or in a JAR file within the WEB-INF/lib directory. The EJB deployment
descriptor is also optional. If you need it, you can package the EJB deployment descriptor as a
WEB-INF/ejb-jar.xml file.
The rules for packaging EJB content in a WAR module are different from
the rules for packaging EJB content in a JAR module. For more information about packaging EJB
content in WAR files, see EJB content in WAR modules
Procedure
- In the Java™ EE perspective,
right-click your Web project and select , or Message-Driven Bean (EJB 3.x),
and click Next.
- On the Create EJB 3.x Session Bean page or the Create Message-Driven
Bean 3.x page, complete the following steps.
- In the Java EE
perspective, right-click your project, and select or . The Create EJB 3.x Session Bean or
Create EJB 3.x Message-Driven Bean wizard appears.
- In the Source folder field, select
the source folder for the new bean.
- In the Java package field, type
the package name for the new bean.
- In the Bean name field, type the name that you
want to assign to the enterprise bean. By convention, bean names begin
with an uppercase letter.
Note: You can use Unicode characters
for the bean name, but Unicode characters are not supported for enterprise
bean packages and classes associated with enterprise beans.
- Select Remote to add a remote interface and select Local
to add a local interface, and click Finish.
- To create a deployment descriptor for your EJB, right-click
your web project and select . An ejb-jar.xml file appears in the WebContent/WEB-INF folder.
- Adding a session bean or message-driven bean using the
deployment descriptor:
- Right-click the ejb-jar.xml file, and
select .
- Click Add. In the Add Item page,
select Enterprise Beans:
- In the title of the page, click 1 error detected.
- For Session Bean, click Add,
then click OK.
- Navigate to your web project, and expand EJBs/Session
Beans, and your new session bean appears.