Java Solaris Communities My SDN Account Join SDN

Previous Previous     Contents     Next Next
Chapter 3

Creating Your First Java EE Application

This chapter gives an overview of the example application and step-by-step instructions on coding the example application.

Architecture of the Example Application

The example application consists of three main components: DukesAgeService, a web service endpoint; DukesBirthdayBean, an enterprise bean; and firstcup, a web application created with JavaServer Faces technology.

DukesAgeService is a JAX-WS endpoint that calculates the age of Duke, the Java mascot. Duke was born on May 23, 1995, when the first demo of Java technology was publicly released.

DukesBirthdayBean is a stateless session bean that calculates the difference between the user's age and Duke's age.

The firstcup web application is a JavaServer Faces application that accesses DukesAgeService to display Duke's age, reads in a date provided by the user, accessesDukesBirthdayBean to calculate who is older, and then displays the difference in years between the user and Duke.

The web application consists of the following:

  • greeting.jsp: A JSP page with which a user can enter a date

  • response.jsp: A JSP page that tells the user whether he or she is older or younger than Duke, based on the date the user entered in the greeting.jsp page

  • DukesBDay.java: A JavaServer Faces managed bean that defines properties to hold the user's birth date, get Duke's current age from the web service, and get the age difference between the user and Duke from the enterprise bean.

  • faces-config.xml: A file used to configure resources for the JavaServer Faces application. In the case of this application, the file configures a resource bundle containing messages, the managed bean, DukesBDay, and the page navigation rules.

  • web.xml: The web application's deployment descriptor, which is used to configure certain aspects of a web application when it is installed. In this case, it is used to provide a mapping to the application's FacesServlet instance, which accepts incoming requests, passes them to the life cycle for processing, and initializes resources.

Tiers in the Example Application

The example application has one web tier component (the firstcupweb client) and two business tier components (the DukesAgeServiceweb service and the DukesBirthdayBeanenterprise bean). The user's web browser is the client tier component, as it accesses the rest of the application through the web tier. The example application does not access the EIS tier.

Java EE Technologies Used in the Example Application

The DukesAgeService web service endpoint is a JAX-WS endpoint The DukesBirthdayBean enterprise bean is a stateless session bean. The firstcupweb client is a JavaServer Faces application that runs in the web container of the Java EE server.

Coding the Example Application

This section describes how to code the example application.

Getting Started

Before you start coding the example, you need to perform some set-up tasks:

  1. Register the server with your NetBeans IDE.

  2. Create a directory for the example you will build.

  3. Specify some settings.

ProcedureRegister the Server with NetBeans

  1. Launch the NetBeans IDE.

  2. From the menu, select Tools->Server Manager.

  3. Click Add Server.

  4. In the Add Server Instance dialog, select Sun Java System Application Server from the Server menu.

  5. (Optional) Enter a name for the server in the Name field.

  6. Click Next.

  7. Click Browse to find the location of the Application Server installation.

  8. Click Next.

  9. Enter the user name you chose when you installed the Application Server in the Admin Username field.

  10. Enter the password for this username in the Admin Password field.

  11. Click Finish.

  12. Click Close.

ProcedureCreate a Directory for the Example

  1. Create another directory at the same level as the example directory and call it myexample. You'll put the First Cup application that you build while following this tutorial in this directory.

  2. Copy the entire bp-project folder from the example directory to the myexample directory.

ProcedureSpecify Some Settings

  1. In the myexample/bp-project directory, copy the build.properties.sample file to build.properties.

  2. Open the build.properties file in a text editor.

  3. Set the javaee.home property to the path of your Application Server installation. Use forward slashes in the path, even if you are on the Windows platform. For example, you would enter C:/myServer instead of C:\myServer.

  4. Set the firstcup.tutorial.home property to the location of your firstcup tutorial installation, such as C:/firstcup.

  5. Change example to myexample in the path specified by the javaee.server.passwordfile property.

  6. Open the admin-password.txt file from the myexample/bp-project directory in a text editor.

  7. Set the AS_ADMIN_PASSWORD property to your Application Server password.

  8. Save the build.properties and admin-password.txt files and close them.

Previous Previous     Contents     Next Next
Company Info Contact Terms of Use Privacy Copyright 1994-2006 Sun Microsystems, Inc.