< 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 used to contain your EJB session bean.
In order for you to create an EJB 3.0 project, you need to have WebSphere® Application Server V7.0, V8.0, or V8.5., 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 V7.0, V8.0, or V8.5:
    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 V7.0, V8.0, or V8.5.
  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. Select Java EE. Click OK. The Java EE perspective opens.
    2. In the Java EE perspective, select File > New > Other > EJB > EJB project.
    3. In the Project name field, type EJBCounterSample. Select Add project to EAR, and click Next. On the Java page, accept the defaults and click Next.
    4. On the EJB Module page, clear Create an EJB Client JAR module to hold the client interfaces and classes and select Generate ejb-jar.xml deployment descriptor:, and click Finish.

      EJB Module page

  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.example.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, which presents you with two options, and you simply select @Stateless - javax.ejb.

      CTRL + 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