Sun java System logo     
Packaging: Sample "B" Sample Application



Packaging: Sample "B" Sample Application


This sample application document contains the following sections:



Overview

Figure 1 illustrates functional isolation of modules. A single EAR file (pkgingBApp.ear) contains two EJB JAR files (pkgingBAppEJB1.jar and pkgingBAppEJB2.jar), and two WAR files (pkgingBAppWAR1.war and pkgingBAppWAR2.war).



Figure 1    Packaging Sample "B"

The Simple Interest and Compound Interest web components are divided into separate WAR files (except for the shared static index.html which is arbitrarily included in pkgingBAppWAR1.war). The two WAR files communicate with each other (specifically index.html from WAR1 accesses CompoundInterest_In.jsp from WAR2). This sample also demonstrates session sharing across WAR modules. SimpleInterest_Out.jsp and CompoundInterest_Out.jsp display the current contents of the session. The session stores the latest values (if any) entered on the forms SimpleInterest_In.jsp and CompoundInterest_In.jsp. This separation of components also demonstrates that shared libraries (DateLibrary.class in this case) need to be included in only one of the modules of the EAR file. In this sample, the common library is included in pkgingBAppWAR1. Including the common library class in more than one does not make a difference as the classloader will, at any one time, load only one copy of the class.

The SimpleInterest and the CompoundInterest EJB components are packaged in separate EJB JAR files. This approach demonstrates cross EJB JAR invocation in an EAR file. This separation of components also demonstrates that shared libraries (Calculator.class in this case) need to be included in only one of the modules of the EAR file. In this sample, it is included in pkgingBAppEJB1. Including the common library class in more than one does not make a difference as the classloader will, at any one time, load only one copy of the class.

The essence of this packaging sample is to illustrate the following concepts:

  • Multi WAR packaging in an EAR

  • Multi EJB JAR packaging in an EAR

  • Cross WAR communication

  • Cross EJB JAR communication

  • Session sharing between two WARs.

  • Session is shared between the two WARs only if the session implementation is marked as distributed (as has been done for this sample). If not, session is kept local (also known as "Lite" session).



Compiling and Assembling the Application

The Command Line Based procedure describes how to assemble and compile the sample using a Command Line Interface (CLI).

To rebuild the entire application from scratch, follow these steps:

  1. Compile and Assemble Packaging Sample B

    Execute asant under <sjsas_install_dir>/samples/packaging/pkgingB/src/.

    The default target core will be executed to rebuild the WAR and EAR files.

  2. Deploy the application.

    Once you have re-created the sample application from scratch, proceed to Deploying the Sample Application.

  3. Clean the web application project area. For example:

    Execute asant clean to remove the sample application's assemble and build directories.

You are now ready to use this ear file for deployment.



Deploying the Sample Application



Select one of the following methods of deploying the application:

  • Command Line Interface (CLI)-based Deployment describes how to manually register the sample application using a Command Line Interface (CLI). This is the fastest means of deploying the application to the application server.

  • Web Interface (GUI)-based Deployment describes how to use the Sun Java (tm) System Deployment Tool to import and deploy the sample application. Alternatively, you can also assemble the application from scratch and deploy it using the Deployment Tool.


Command Line Interface (CLI)-based Deployment

Since a complete EAR 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 would like to experience deploying through a GUI tool, then follow instructions in Web Interface (GUI)-based Deployment.

The pre-built pkgingBApp.ear file is a Enterprise Archive file that contains the Web Archive (WAR) file of the application. Within the WAR file resides the XML deployment descriptor files, application class files, JSPs and other content required by the application.

Deploying the pre-built pkgingBApp.ear file is simple. Deploy either Using asant script or Using asadmin command.


Using asant script

  1. Go to the src directory of the sample. For example: <sjsas_install_dir>/samples/packaging/pkgingB/src.

  2. Execute the following command:

    asant deploy


Using asadmin command

  1. Go to the root of the sample directory. For example:

    <sjsas_install_dir>/samples/packaging/pkgingB/

  2. Execute asadmin to deploy the module to the local application server instance. For example:

    asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> pkgingBApp.ear

The deployment process involves the following operations:

  • Authenticates against the local application server's administrative server.

  • The EAR file is transferred to the administrative server.

  • The administrative server begins the registration process:

    • Parses the EAR file and embedded WAR file

    • Explodes the bits into repository

    • Registers the application pkgingBApp by updating server.xml.

If you would like to verify the registration of the application, proceed to Verifying Registration. Otherwise, you are now ready to exercise the application by Running the Sample Application.


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, do one of the following:

  • Execute asadmin to look at applications deployed with a server instance. For example:

    asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>

  • Navigate the Admin tool GUI to App Server Instances>server1>Applications>Enterprise Apps.

    Click on Enterprise Apps on the left frame menu to display a list of applications deployed on server.


Web Interface (GUI)-based Deployment

Since a pre-built Enterprise Archive (EAR) file for the sample application is included with the application server, you can use the Admin Tool to quickly read in the .ear file and deploy it to the application server.

  1. Open the pre-existing sample EAR file.

  2. Start the admin server if it is not already started:

  3. UNIX:

    Go to <sjsas_install_dir>/domains/domain1/admin-server/bin

    Execute startserv

  4. Windows:

    Go to <sjsas_install_dir>\domains\domain1\admin-server\bin

    Run startserv

  5. Open the EAR file:

    Navigate to the browser based admin server page [http://<server-host>:<admin-port>/index.html].

  6. Enter your username and password to access the admin server

  7. Click on App Server Instances>server1>Applications>Enterprise Apps

  8. In the right hand pane, click on Deploy to deploy an application. Choose the file (from disk) to be deployed pkgingBApp.ear and Click OK.

  9. You will be asked for the application name. Enter pkgingBApp and Click OK.

If the deployment goes through fine, you will see the original pane with pkgingBApp application as deployed.



Running the Sample Application



To run the application, go to the following URL: http://<hostname>:<port>/pkgingB1

Traverse the JSP and Servlet links to execute each simple web sample application.



Generating Javadocs


 
To understand sample application source code better, you can refer to the related javadocs.

To generate javadocs run the following command from the src directory

asant javadocs

or

asant all

After javadocs are generated, you can access them at

<install_dir>/samples/packaging/pkgingB/javadocs/index.html


Troubleshooting



  • Although the war, ear, context-root and servlet alias names in this sample are all pkgingBApp, it is not necessary that it be so. The application will work as expected if the names of each of these attributes is unique. Rebuild the app after changing the context-root (in application.xml), the servlet alias (in web.xml) and the war and ear names, redeploy and test the sample to confirm this.

  • If you encounter problems when running the application, review the log files at <sjsas-install-dir>/domains/domain1/<server-instance>/logs/server.log to learn what exactly went wrong.

Some Known Issues:

  • The sample can not be deployed from the application server administration GUI, if Run verifier option is selected. Solution is, try deploying the application without Run verifier, or deploy using asant.

  • The sample can not be deployed using asadmin with option --verify=true. Solution is, try deploying the application without the option --verify=true, or deploy using asant.


Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated August 13, 2002