Packaging EJB content in web application archive (WAR) modules

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

  1. In the Java™ EE perspective, right-click your Web project and select New > Other > Session Bean (EJB 3.x), or Message-Driven Bean (EJB 3.x), and click Next.
  2. On the Create EJB 3.x Session Bean page or the Create Message-Driven Bean 3.x page, complete the following steps.
    1. In the Java EE perspective, right-click your project, and select New > Session Bean or New > Message-Driven Bean. The Create EJB 3.x Session Bean or Create EJB 3.x Message-Driven Bean wizard appears.
    2. In the Source folder field, select the source folder for the new bean.
    3. In the Java package field, type the package name for the new bean.
    4. 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.
    5. Select Remote to add a remote interface and select Local to add a local interface, and click Finish.
  3. To create a deployment descriptor for your EJB, right-click your web project and select Java EE > Generate EJB Deployment Descriptor Stub. An ejb-jar.xml file appears in the WebContent/WEB-INF folder.
  4. Adding a session bean or message-driven bean using the deployment descriptor:
    1. Right-click the ejb-jar.xml file, and select Open With > EJB Deployment Descriptor Editor.
    2. Click Add. In the Add Item page, select Enterprise Beans:
      Add EJB to WAR
    3. In the title of the page, click 1 error detected.
    4. For Session Bean, click Add, then click OK.
    5. Navigate to your web project, and expand EJBs/Session Beans, and your new session bean appears.
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: tejbsinwars.html