Deploying a J2EE Application
Deploying a J2EE Application
This tutorial covers how to create a data source and deploy
a J2EE application to Oracle Application Server 10g by using Oracle Enterprise
Manager 10g Application Server Control.
Approximately 30 minutes
This tutorial covers the following topics:
Place the cursor over this icon to load and view all
the screenshots for this tutorial. (Caution: Because this action loads all screenshots
simultaneously, response time may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor
over each individual icon in the following steps to load and view only the screenshot
associated with that step.
Oracle Application Server 10g provides a complete
Java 2, Enterprise Edition (J2EE) environment written entirely in Java that
executes on the Java Virtual Machine (JVM) of the standard Java Development
Kit (JDK). You can run Oracle Application Server Containers for J2EE 10g
(OC4J) on the standard JDK that exists on your operating system. OC4J is a fast,
lightweight, highly scalable, and easy-to-use J2EE server that is fully J2EE
1.3 compatible.
Oracle Application Server 10g is built entirely on
a J2EE framework that supports the latest industry standard technologies and
programming languages, including J2EE API specifications, XML, and Web services.
This comprehensive and flexible framework enables you to design, develop, and
deploy dynamic Web sites, portals, and transactional applications by using familiar
programming languages and technologies such as servlets, JavaServer pages, XML,
PL/SQL Server Pages, and SOAP. Oracle Application Server 10g also provides
comprehensive Web services to expose business functions to authorized parties
over the Internet from any Web device.
The Oracle Application Server 10g environment is managed
by Oracle Enterprise Manager 10g Application Server Control. Using the
Web-based Application Server Control Console, administrators can:
- Manage and configure application server components
- Monitor server performance
- Access a graphical view of their server environment
- Deploy and monitor J2EE applications
- Manage port values across application server components
- View server and application diagnostic logs
The HR demo application provides support for retrieving the
department and employee details from an Oracle database. The application displays
a main welcome page from where you can navigate to department, and employee
pages. Using a search field, you can search for employees by name. When you
deploy the HR application (hrapp.ear) by using Application Server Control's
deployment wizard, the application is deployed to the OC4J instance. The Web
application is bound to a URL context so that you can access the application
from OC4J.
Back to Topic List
Before starting this tutorial, you should:
| 1. |
Install the J2EE and Web Cache
Middle Tier component of Oracle Application Server 10g. |
| 2. |
Set the environment variable ORACLE_HOME to point to
the directory in which the Oracle Application Server 10g software
is installed.
|
| 3. |
Set the PATH environment variable to include the $ORACLE_HOME/bin,
$ORACLE_HOME/dcm/bin, and $ORACLE_HOME/opmn/bin
|
| 4. |
Have access to an Oracle 10g database. The database
must have the HR sample schema installed. You must be aware of your HR
schema password.
|
| 5. |
Download the sample application (j2ee.zip) from here. Extract the contents of j2ee.zip to a directory. This directory (referred to as <wkdir> in this tutorial) then contains the application. |
Back to Topic List
A data source can be created at two levels: (1) Container
level which is meant for all applications deployed to an OC4J, and (2) Application
level which is meant for a specific application. In this tutorial, a container-level
data source will be created. This data source provides access to the HR schema
used to store data for the hrapp application. To create a data source, perform
the following steps:
| 1. |
Start Oracle Enterprise Manager 10g Application
Server Control from a command window, if it is not already running,
with the following command:
emctl start iasconsole

|
| 2. |
Open your browser and enter the following URL: http://<hostname>.<domain>:1810/.
Note: The administration port number is automatically assigned at installation
time and may be different for your installation. When prompted for user
name and password, enter ias_admin and the password that you entered
at installation time, such as welcome1.

|
| 3. |
On the Application Server Control Console's Home page, view the System
Components table.
Start the HTTP Server and the home OC4J components if they are
not already running.
Do this by selecting the check box next to each component and then clicking
the Start button on the components table (on the left corner).
Then select OC4J home link from the list to navigate to the OC4J
home component page.

|
| 4. |
The OC4J home component page comes up with the Home page
link that provides status and performance information for this OC4J
component. Use the Applications property page link to view and
manage the J2EE applications that have been deployed to the container
and information on their usage and performance. On the Administration
property page, you can manage the OC4J configuration. To define data
sources, click the Administration property page.

|
| 5. |
On the Administration property page, under Application Defaults,
click Data Sources to manage the container-level data sources.

|
| 6. |
On the Data Sources page, click Create to create a container-level
data source.

|
| 7. |
On the Create Data Source page, enter (or copy and paste) these
values in the following fields (other fields should remain blank).
Tip: To create additional data sources in the future, you can use
the Create Like option to avoid retyping all the data.
 |
Name: HRDS |
 |
Data Source Class: com.evermind.sql.DriverManagerDataSource |
 |
JDBC URL: jdbc:oracle:thin:@localhost:listening
port:sid
Note: You may need to replace localhost with the host name
or the IP address of the server where the Oracle database software
is installed and running. You must also replace the listening port
and the Sid with actual values. |
 |
JDBC Driver: oracle.jdbc.driver.OracleDriver |
 |
Username: hr |
 |
Password: hr |
 |
Location: jdbc/hrCoreDS |
 |
Transactional (XA) Location: jdbc/xa/hrXADS |
 |
EJB Location: jdbc/hrDS (This
is the Data Source you specified for the entity beans on deploying
the application.) |
 |
Connection Retry Interval (seconds):
1 |
 |
Cached Connection Inactivity Timeout
(seconds): 30 |
Scroll down to the bottom of the page and click Create to create
the data source.


|
| 8. |
The Confirmation page indicates that the data source has been
created. You are prompted to restart the home OC4J server before the changes
can take effect. Click Yes.

|
| 9. |
The following page is displayed and updated while the OC4J home instance
is restarted. Wait until you get confirmation that the OC4J instance has
started.

|
| 10. |
On the Confirmation page indicating that the OC4J home instance be restarted,
click OK.

|
| 11. |
The new data source HRDS should appear in the Data Sources list.

|
Back to Topic List
You can access the HR application files from
the j2ee subfolder of the directory where you have extracted the j2ee.zip file in step 5 of the prerequisite.
The HR application illustrates how to use the latest
J2EE 1.3 features such as EJB local interfaces, Container Managed Relationships,
EJB QL, Servlet Filters, and JSP Tag Library.
Application Files
The application includes the following files:
|
META-INF/ |
| |
 |
application.xml: application deployment
descriptor |
 |
hrejb/ |
| |
 |
META-INF/ |
| |
|
- |
ejb-jar.xml: EJB deployment descriptor |
| |
|
- |
orion-ejb-jar.xml: EJB deployment descriptor |
| |
 |
hr/: HR package |
| |
|
- |
impl/: Entity bean implementation |
| |
|
|
- DepartmentsBean.java: Departments entity
bean |
| |
|
|
- EmployeesBean.java: Employees entity
bean |
| |
|
- |
Departments.java: Departments bean remote
interface |
| |
|
- |
DepartmentsHome.java: Departments bean
home interface |
| |
|
- |
DepartmentsLocal.java: Departments bean
local interface |
| |
|
- |
DepartmentsLocalHome.java: Departments
bean local home interface |
| |
|
- |
Employees.java: Employees bean remote interface |
| |
|
- |
EmployeesHome.java: Employees bean home
interface |
| |
|
- |
EmployeesLocal.java: Employees bean local
interface |
| |
|
- |
EmployeesLocalHome.java: Employees bean
local home interface |
 |
hrweb/ |
| |
 |
WEB-INF/ |
| |
|
- |
classes/: Servlet and Filter classes |
| |
|
|
- filter/: Filter package |
| |
|
|
LogFilter.java: Log Filter |
| |
|
|
TimerFilter.java: Timer Filter |
| |
|
- |
lib/: Tag libraries |
| |
|
|
- ejbtaglib.tar/: EJB tag library |
| |
|
- |
web.xml: Web deployment descriptor |
| |
 |
index.html: Welcome page |
| |
 |
departments.jsp: List all departments |
| |
 |
employees.jsp: List all employees or employees
by department |
| |
 |
search.jsp: Search employees by name |
| |
 |
blaf.css: Stylesheet used by all JSPs |
| |
 |
logo.gif: Oracle logo |
| |
 |
background.gif: Background image |
 |
common.xml: Common setup file for ant |
 |
build.xml: Build file used by ant |
Explanation of Files
| 1. |
The HR application contains two container managed
persistence entity beans (based on Departments and Employees tables in
the HR demo schema) using EJB 2.0 abstract schema and local interfaces;
the source files of the entity beans are located in \<wkdir>\j2ee\hrejb\hr.
You can examine the code to see how the beans are implemented. The entity
beans also use Container Managed Relationships and EJB query language.
Examine the EJB deployment descriptors (ejb-jar.xml and orion-ejb-jar.xml
located in \<wkdir>\j2ee\hrejb\META-INF) to see how the relationships
are defined and how the Finder method uses the EJB query language.
|
| 2. |
The HR application uses OracleJSP EJB tags in Java Server Pages to access
the entity beans. You can examine departments.jsp and employees.jsp in
the \<wkdir>\j2ee\hrweb directory to see how the EJB tags work.
|
| 3. |
The application also contains two Servlet Filters: the LogFilter keeps
track of the requested URLs and the TimerFilter times the execution of
requests; the two filters are chained. You can examine the source files
in the \<wkdir>\j2ee\hrweb\WEB-INF\classes\filter and the web deployment
descriptor in the \<wkdir>\j2ee\hrweb\WEB-INF\web-xml directories
to see how the filters are defined and chained together.
|
| 4. |
The application has already been built for you. You should be able to
find the EAR file in \<wkdir>\j2ee\build (hrapp.ear).
|
Back to Topic
List
Now, you are ready to deploy the application. Perform
the following steps:
| 1. |
On the Data Sources page, click the OC4J:
home link to go back to the Home page of the OC4J home component.

|
| 2. |
Click the Applications property page link to display the applications
for the home instance. Click the Deploy EAR file button to launch
the Deploy Application Wizard.

|
| 3. |
The Deploy Application Wizard in Application Server Control will guide
you through the steps required to deploy an application. On the Deploy
Application page, click Browse..., to select the hrapp.ear
from the \<wkdir>\j2ee\build directory as the EAR file to
deploy. Enter hrapp as the application name. Click Continue.

|
| 4. |
On the Deploy Application: URL Mapping for Web Modules page, check
whether /hrapp is specified as the URL Mapping for the application.
Click Next.

|
| 5. |
On the Deploy Application: Resource Reference Mappings page, you
see jdbc/hrDS in the Data Source field for the Employees
and Departments Entity Bean, respectively. You already defined the jdbc/hrDS
data source. Click Next.

|
| 6. |
Oracle Application Server 10g provides a Java Authentication
and Authorization Service (JAAS) user provider that can be used for J2EE
application security management. The default user manager service, in
Oracle Application Server 10g, is also known as JAZN. On the
Deploy Application: User Manager page, accept the default setting
Use JAZN XML User Manager. Click Next.

|
| 7. |
On the Deploy Application: Review page, check the deployment information
summary, that is, the EAR File to Deploy, Deployment Destination, and
URLs Mapped to Application. Note that the application does not contain
any Web Services modules, and notice the TIP on the review page
indicating that the HTTP server will be restarted after deployment to
pick up the new URL mappings. Click Deploy to deploy the application.

|
| 8. |
During deployment, the Application Server Control Console may display
a page tracking the deployment process. Wait until you get the Confirmation
page. When the Confirmation page is displayed, click OK.


|
| 9. |
After the application has been deployed, Application Server Control brings
you back to the Applications property page of the OC4J home instance.
Note that the hrapp appears in the Deployed Applications list. Click
the hrapp link to access that application's page.

|
| 10. |
On the Application: hrapp page, you see the component modules
of the application. Click the EJB Module hrejb link.

|
| 11. |
You can now click Departments to see the EJB itself.

|
| 12. |
The EJB information is now displayed.
Note: When the application is not accessed, there is no load displayed
in the performance metrics. When the application is accessed, the data
on the page is refreshed and you can monitor the application's performance
by using the Application Server Control.

|
Back to Topic List
Now, you are ready to test the application. Use Application
Server Control to determine the HTTP Server port. 7777 is the default HTTP server
port. Start by running the application by using the Oracle HTTP Server as the
Web server. Perform the following steps:
| 1. |
Enter the following URL to run the HR application
from the browser:
http://<hostname>.<domain>:<HTTP-PORT>/hrapp/.
You should be able to see the application main welcome page. Click Departments.
Note: The HTTP Server port is automatically assigned at installation time
and may be different for your installation.

|
| 2. |
A list containing all the departments in the HR database that you configured
as the hrapp data source is displayed. Note that this invokes departments.jsp.
Select a department such as Human Resources.

|
| 3. |
A list of Employees in the department selected is displayed. Click
Back twice to return to the HR application main menu.

|
| 4. |
Click Employees.

|
| 5. |
You see a list of all employees in the HR database. Then, click Back
to return to the HR application main menu.

|
| 6. |
You can also search for employees by name. Click Search.

|
| 7. |
Enter John as the first name and click Search.

|
| 8. |
You see a list containing all the employees whose first name is John.

|
You can now return to the browser that displays the Application
Server Control. Navigate to the hrapp application page. Click on EJB Module
hrejb link. Click Departments to view the EJB performance metrics. Note the
difference in the performance metrics.
Back to Topic List
In this lesson, you've learned how to
monitor the performance of the application by using Application Server Control.
You also learned how to:
|
Create a Data Source
|
|
Deploy the HR J2EE Application
|
|
Run the HR Application
|
Back to Topic List
|
To learn more about Oracle Application Server Containers for J2EE (OC4J),
refer to the additional information on the OTN
Web site.
|
 |
To ask a question about this OBE tutorial, post a query on the OBE
Discussion Forum. |
Back to Topic List
Place the cursor over this icon to hide all screenshots.
|