The Java EE 6 Tutorial

Building, Packaging, Deploying, and Running the cart Example

Now you are ready to compile the remote interface (Cart.java), the home interface (CartHome.java), the enterprise bean class (CartBean.java), the client class (CartClient.java), and the helper classes (BookException.java and IdVerifier.java). Follow these steps.

You can build, package, deploy, and run the cart application using either NetBeans IDE or the Ant tool.

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

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

  2. In the Open Project dialog, navigate to:


    tut-install/examples/ejb/
    
  3. Select the cart folder.

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

  5. Click Open Project.

  6. In the Projects tab, right-click the cart project and select Deploy.

    This builds and packages the application into cart.ear, located in tut-install/examples/ejb/cart/dist/, and deploys this EAR file to your GlassFish Server instance.

  7. To run the cart application client, select Run->Run Main Project.

    You will see the output of the application client in the Output pane:


    ...
    Retrieving book title from cart: Infinite Jest
    Retrieving book title from cart: Bel Canto
    Retrieving book title from cart: Kafka on the Shore
    Removing "Gravity’s Rainbow" from cart.
    Caught a BookException: "Gravity’s Rainbow" not in cart.
    Java Result: 1
    run-cart-app-client:
    run-nb:
    BUILD SUCCESSFUL (total time: 14 seconds)

ProcedureTo Build, Package, Deploy, and Run the cart Example Using Ant

  1. In a terminal window, go to:


    tut-install/examples/ejb/cart/
  2. Type the following command:


    ant
    

    This command calls the default target, which builds and packages the application into an EAR file, cart.ear, located in the dist directory.

  3. Type the following command:


    ant deploy
    

    The cart.ear file is deployed to the GlassFish Server.

  4. Type the following command:


    ant run
    

    This task retrieves the application client JAR, cartClient.jar, and runs the application client. The client JAR, cartClient.jar, contains the application client class, the helper class BookException, and the Cart business interface.

    This task is equivalent to running the following command:


    appclient -client cartClient.jar
    

    When you run the client, the application client container injects any component references declared in the application client class, in this case the reference to the Cart enterprise bean.

The all Task

As a convenience, the all task will build, package, deploy, and run the application. To do this, enter the following command:


ant all