< Previous | Next >

Lesson 1.1: Create an EJB 3.0 project

This lesson leads you through the detailed steps to create an EJB 3.0 project that you will use to contain your EJB session bean.
In order for you to create an EJB 3.0 project, you need to have the WebSphere® Application Server version 6.1 with the EJB 3.0 Feature Pack installed OR WebSphere Application Server version 7.0, and to have a profile created for this server.
TO create an EJB 3.0 counter project:
  1. Create a server configuration for the WebSphere Application Server version 6.1 with the Fixpack for EJB3 or version7.0:
    1. Open the Servers view by selecting Window > Show View > Servers.
    2. Define a new WebSphere Application Server by right clicking the Servers view and selecting New > Server. Follow the instructions in the New Server wizard, ensuring that you select the WebSphere Application Server version 6.1 with the Fixpack for EJB3 or version 7.0.
  2. Create an EJB 3.0 project:
    1. If the Java™ EE icon, J2EE perspective, does not appear in the top right tab of the workspace, you need to switch to the Java EE perspective. From the menu bar, select Window > Open Perspective > Other. The Select Perspective window opens.
    2. Select Java EE. Click OK. The Java EE perspective opens.
    3. In the Java EE perspective, select File > New > Other > EJB > EJB project.
    4. In the Project name field, type EJBCounterSample. Select Add project to EAR, and Next.
    5. On the EJB Module page, clear Create an EJB Client JAR module to hold the client interfaces and classes:

      EJB Module page

    6. Accept the other default values and click Finish.
  3. Add a Java class, @Stateless annotation:
    1. In the Enterprise explorer view, right click the EJBCounterSample project and select New > Class.
    2. Accept the default Source folder (EJBCounterSample/ejbModule). In the Package field, type com.ibm.websphere.ejb3sample.counter, and in the Name field, type StatelessCounterBean.
    3. Click Finish.
    4. Your StatelessCounterBean class opens in the Java Editor. Add the EJB 3.0 annotation to generate a session bean by adding @Stateless:
      @Stateless annotation
    5. When you press CTRL+S to save, you can see a quick fix icon quick fix icon beside the @Stateless line.
    6. Right click the quick fix icon and select Quick Fix:
      Quick Fix
    7. Select Import 'Stateless' (javax.ejb) and press CTRL+S to save:
      Add Import 'Stateless' (javax.ejb)
      The required dependencies are automatically added to the source code.
      Tip: A shortcut to using the Quick Fix is to type @Sta, and press CTRL+Spacebar. This will present you with two options, and you simply select @Stateless - javax.ejb.

      Cntrl + Space options

      The required dependencies are automatically added to the source code.
You now are ready to move on to Exercise 1.2, Create required classes and interfaces for the StatelessCounterBean.
< Previous | Next >

Feedback