The Java EE 6 Tutorial, Volume I

Building, Packaging, Deploying, and Running the guessnumber Example

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

ProcedureBuilding and Deploying the guessnumber Example Using NetBeans IDE

Follow these instructions to build, package, and deploy the guessnumber example to the Enterprise Server using NetBeans IDE.

This procedure builds the application into the tut-install/examples/cdi/guessnumber/build/web directory and deploys the contents of this directory to the Enterprise Server.

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

  2. In the Open Project dialog, navigate to tut-install/examples/cdi/.

  3. Select the guessnumber folder.

  4. Select the Open as Main Project checkbox.

  5. Click Open Project Folder.

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

ProcedureBuilding, Packaging, and Deploying the guessnumber Example Using Ant

Follow these instructions to build, package, and deploy the guessnumber example to the Enterprise Server using Ant.

This procedure builds the application into the tut-install/examples/cdi/guessnumber/build/web directory and deploys the contents of this directory to the Enterprise Server.

This procedure builds and packages the application into guessnumber.war, located in tut-install/examples/cdi/guessnumber/dist/, and deploys this WAR file to the Enterprise Server.

  1. In a terminal window, go to this directory:


    tut-install/examples/cdi/guessnumber/
  2. Type the following command:


    ant
    

    This command calls the default target, which builds and packages the application into a WAR file, guessnumber.war, located in the dist directory.

  3. Type the following command:


    ant deploy
    

    The guessnumber.war file will be deployed to the Enterprise Server.

ProcedureRunning the guessnumber Example

  1. In a web browser, type the following URL:


    http://localhost:8080/guessnumber

    The Guess My Number page opens, as shown in Figure 18–2.

    Figure 18–2 Guess My Number Example

    Guess Number example at beginning of game

  2. Type a number in the Number text field, then click Guess.

    The minimum and maximum values are modified, along with the remaining number of guesses.

  3. Keep guessing numbers until you get the right answer or run out of guesses.

    If you get the right answer, the input field and Guess button are grayed out, as shown in Figure 18–3.

    Figure 18–3 Guess My Number at End of Game

    Guess Number example at end of game

  4. Click the Reset button to play the game again with a new random number.