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:
Register the server with your NetBeans IDE.
Create a directory for the example you will build.
Specify some settings.
Register the Server with NetBeans
Launch the NetBeans IDE.
From the menu, select Tools->Server Manager.
Click Add Server.
In the Add Server Instance dialog, select Sun Java System Application Server from the Server menu.
(Optional) Enter a name for the server in the Name field.
Click Next.
Click Browse to find the location of the Application Server installation.
Click Next.
Enter the user name you chose when you installed the Application Server in the Admin Username field.
Enter the password for this username in the Admin Password field.
Click Finish.
Click Close.
Create a Directory for the Example
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.
Copy the entire bp-project folder from the example directory to the myexample directory.
Specify Some Settings
In the myexample/bp-project directory, copy the build.properties.sample file to build.properties.
Open the build.properties file in a text editor.
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.
Set the firstcup.tutorial.home property to the location of your firstcup tutorial installation, such as C:/firstcup.
Change example to myexample in the path specified by the javaee.server.passwordfile property.
Open the admin-password.txt file from the myexample/bp-project directory in a text editor.
Set the AS_ADMIN_PASSWORD property to your Application Server password.
Save the build.properties and admin-password.txt files and close them.

Previous