The Java EE 6 Tutorial

ProcedureTo Build, Package, Deploy, and Run the clientmdbentity Example Using NetBeans IDE

  1. In NetBeans IDE, select File->Open Project.

  2. In the Open Project dialog, navigate to:


    tut-install/examples/jms/
    
  3. Select the clientmdbentity folder.

  4. Select the Open as Main Project check box and the Open Required Projects check box.

  5. Click Open Project.

  6. In the Projects tab, right-click the clientmdbentity project and select Build.

    This task creates the following:

    • An application client JAR file that contains the client class and listener class files, along with a manifest file that specifies the main class

    • An EJB JAR file that contains the message-driven beans and the entity class, along with the persistence.xml file

    • An application EAR file that contains the two JAR files along with an application.xml file

  7. If the Java DB database is not already running, follow these steps:

    1. Click the Services tab.

    2. Expand the Databases node.

    3. Right-click the Java DB node and select Start Server.

  8. In the Projects tab, right-click the project and select Run.

    This command deploys the project, returns a client JAR file named clientmdbentityClient.jar and then executes it.

    The output of the application client in the Output pane looks something like this:


    PUBLISHER: Setting hire ID to 50, name Bill Tudor, position Programmer
    PUBLISHER: Setting hire ID to 51, name Carol Jones, position Senior Programmer
    PUBLISHER: Setting hire ID to 52, name Mark Wilson, position Manager
    PUBLISHER: Setting hire ID to 53, name Polly Wren, position Senior Programmer
    PUBLISHER: Setting hire ID to 54, name Joe Lawrence, position Director
    Waiting for 5 message(s)
    New hire event processed:
      Employee ID: 52
      Name: Mark Wilson
      Equipment: PDA
      Office number: 294
    Waiting for 4 message(s)
    New hire event processed:
      Employee ID: 53
      Name: Polly Wren
      Equipment: Laptop
      Office number: 186
    Waiting for 3 message(s)
    New hire event processed:
      Employee ID: 54
      Name: Joe Lawrence
      Equipment: Java Phone
      Office number: 135
    Waiting for 2 message(s)
    New hire event processed:
      Employee ID: 50
      Name: Bill Tudor
      Equipment: Desktop System
      Office number: 200
    Waiting for 1 message(s)
    New hire event processed:
      Employee ID: 51
      Name: Carol Jones
      Equipment: Laptop
      Office number: 262

    The output from the message-driven beans and the entity class appears in the server log, wrapped in logging information.

    For each employee, the application first creates the entity and then finds it. You may see runtime errors in the server log, and transaction rollbacks may occur. The errors occur if both of the message-driven beans discover at the same time that the entity does not yet exist, so they both try to create it. The first attempt succeeds, but the second fails because the bean already exists. After the rollback, the second message-driven bean tries again and succeeds in finding the entity. Container-managed transactions allow the application to run correctly, in spite of these errors, with no special programming.

    You can run the application client repeatedly.