![]() |
Lifecycle Simple Sample Application |
Lifecycle Simple Sample Application
This document describes how to utilize the Lifecycle Simple sample application in conjunction with the Sun Java (tm) System Application Server 7.This sample application document contains the following sections:
Overview
Compiling and Assembling the Application
Deploying the Sample Application
Overview
This sample is based on the LifecycleListener interface support provided by Sun Java (tm) System Application Server. This sample demonstrates the use of events generated by the application server during its lifecyle - namely, INIT, START, READY, STOP, and TERMINATE.The following instructions describe how to assemble, deploy on the Application Server, and how to run the application. Although the sample application offers minimal functionality, this sample should provide you with a basic understanding of startup class support in the Sun Java (tm) System Application Server.
Compiling and Assembling the Application
This Command Line Based Compilation and Assembly procedure describes how to assemble and compile the sample using a Command Line Interface (CLI).
Command Line Based Compilation and Assembly
To rebuild the entire application from scratch:
Compile and Assemble.
Deploy the application.
- Execute the asant command under <install_dir>/samples/lifecycle/simple/src/
- [please add <install_dir>/bin to your path]
- The default target core is executed to rebuild the .jar file.
Clean the application project area.
- When you have re-created the sample application from scratch, proceed to Deploying the application.
- Execute the asant clean command to remove the sample application's assemble and build directories.
- Now you are ready to use this .jar file for deployment.
Deploying the Sample Application
Select one of the following approaches to deploy the application:
Command Line Based Deployment describes how to manually register the application in a Sun Java (tm) System Application Server using a Command Line Interface (CLI). This is the fastest means of deploying the application.
GUI Based Deployment describes how to use the Sun Java (tm) System Deployment Tool to import and deploy the sample application.
Command Line Based Deployment
Since a complete .jar file is supplied, the fastest means of setting up the application is to use the command line utilities as described in this section.If you want to deploy through a GUI tool, follow the instructions for GUI Based Deployment.
The pre-built lifecycle-simple.jar file contains the Java Archive (JAR) files of the application.
Deploy using either the asant script or the asadmin command.
Go to the src directory of the sample:
Execute the asant deploy command.
- <install_dir>/samples/lifecycle/simple/src
Go to the root of the sample directory:
The deployment process involves the following operations:
Execute the asadmin command to deploy the application to the local application server instance:
- <install_dir>/samples/lifecycle/simple/
- asadmin create-lifecycle-module -u <user-name> -w <password> -H <hostname> -p <admin server port> --classname samples.lifecycle.simple.LifecycleListenerImpl --classpath <install_dir>/samples/lifecycle/simple/src/../lifecycle-simple.jar lifecycle-simple
It authenticates against the local application server's administrative server.
The .jar file is transferred to the administrative server.
The administrative server begins the registration process:
Parses the .jar file.
Explodes the bits into the repository.
Registers the J2EE application lifecycle-simple by updating the server.xml file.
- If you want to verify the registration of the application, proceed to the Verifying Registration section.
- Otherwise, you are ready to exercise the application by Running the Sample Application.
GUI Based Deployment
Since a pre-built (.jar) file for the sample application is included with the application server, you can use the Admin Tool to quickly read in the .jar file and deploy it to the application server.
Start the admin server if it is not already started.
- UNIX
Open the .jar file.
- Windows
Navigate to the browser based admin server page [http://<server-host>:<admin-port>/index.html].
Enter your username and password to access the admin server.
Click App Server Instances>server1>Applications>Lifecycle Modules.
In the right hand pane, click Deploy to deploy an application.
Fill in the Module Name, Classname and Classpath.
Fill in Load order(Optional). Load order expects integer value which can be used to force the order in which deployed lifecycle modules are loaded at server startup. Smaller numbered modules get loaded sooner. Order is unspecified if two or more lifecycle modules have the same load-order value.
You may also choose the relevent boolean values for Fatal faliure.
You must also set the Enable flag to true in order to load this module at the time of server startup.
A typical set of values for these attributes will be:
- Name lifecycle-simple
- ClassName samples.lifecycle.simple.LifecycleListenerImpl
- ClassPath
/samples/lifecycle/simple/src/../lifecycle-simple.jar
- Click OK.
- If the deployment goes through properly, you see the original pane with the lifecycle-simple application as deployed.
Verifying Registration
As an optional step, you can use the Sun Java (tm) System Application Server Administration Tool to verify that the application has been registered.If you do not want to verify that the application has been registered, proceed directly to Running the Sample Application.
To verify the registration of the application:
Execute the asadmin command to look at applications deployed with a server instance. You see lifecycle-simple as one of the listed applications.
Or navigate the Admin tool GUI to
- asadmin list-components -u <username> -w <password> -H <host> -p <admin-port><server instance name>.
App Server Instances>server1>Applications>Lifecycle ModulesClick Lifecycle modules on the left frame menu to display a list of applications deployed on the server.
Running the Sample Application
Since this is a startup class, you need to stop and start the application server instance.
asadmin stop-instance - H <hostname> -p <admin server port> -u <user-name> -w <password> <server-instance name>
asadmin start-instance -H <hostname> -p <admin server port> -u <user-name> -w <password> <server-instance name>
- After the server has started, go to the log file of the server instance and you see the following output:
- ...
- LifecycleTopic:INIT_EVENT
- LifecycleTopic:START_EVENT
Generating Javadocs
To understand sample application source code better, you can refer to the related javadocs. To generate javadocs, run the command
After javadocs are generated, you can access them at
- asant javadocs
- or
- asant all
<install_dir>/samples/lifecycle/simple/javadocs/index.html
Troubleshooting
If you encounter problems when running the application, review the log files at <install-dir>/domains/domain1/<server-instance>/logs/server.log to see what went wrong.Make certain that you run asant undeploy before redeploying this sample to make sure that all modules are undeployed and the resources are disabled.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated July 10, 2002