The Java EE 6 Tutorial

Building, Packaging, Deploying, and Running the simplegreeting CDI Example

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

ProcedureTo Build, Package, and Deploy the simplegreeting Example Using NetBeans IDE

This procedure builds the application into the following directory:

tut-install/examples/cdi/simplegreeting/build/web

The contents of this directory are deployed to the GlassFish Server.

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

  2. In the Open Project dialog, navigate to:


    tut-install/examples/cdi/
    
  3. Select the simplegreeting folder.

  4. Select the Open as Main Project check box.

  5. Click Open Project.

  6. (Optional) To modify the Printer.java file, perform these steps:

    1. Expand the Source Packages node.

    2. Expand the greetings node.

    3. Double-click the Printer.java file.

    4. In the edit pane, comment out the @Informal annotation:

      //@Informal
      @Inject
      Greeting greeting;
    5. Save the file.

  7. In the Projects tab, right-click the simplegreeting project and select Deploy.

ProcedureTo Build, Package, and Deploy the simplegreeting Example Using Ant

  1. In a terminal window, go to:


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


    ant
    

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

  3. Type the following command:


    ant deploy
    

    Typing this command deploys simplegreeting.war to the GlassFish Server.

ProcedureTo Run the simplegreeting Example

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


    http://localhost:8080/simplegreeting

    The Simple Greeting page opens.

  2. Type a name in the text field.

    For example, suppose that you type Duke.

  3. Click the Say Hello button.

    If you did not modify the Printer.java file, the following text string appears below the button:


    Hi, Duke!

    If you commented out the @Informal annotation in the Printer.java file, the following text string appears below the button:


    Hello, Duke.

    Figure 19–1 shows what the application looks like if you did not modify the Printer.java file.

    Figure 19–1 Simple Greeting Application

    Simple Greeting application