Sun Java System logo     
Packaging: Sample "C" Sample Application



Packaging: Sample "C" Sample Application


This sample application document contains the following sections:



Overview

Figure 1 illustrates how a remote client can access an EJB deployed as a stand-alone module on a Sun Java (tm) System application server. The EJB module contains a single EJB named ModuleEJB and accesses few utility classes.



Figure 1    Packaging Sample "C"

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

  • Stand-alone module registration for the EJB JAR module

  • RMI-IIOP (Non ACC) client access to an EJB.

You may refer to Running the Sample Application for instructions on running the sample. To better understand sample application source code, you can generate javadocs using asant javadocs and access them at <install_root>/samples/packaging/pkgingC/javadocs/index.html.



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 C

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

    The default target core will be executed to rebuild the EJB JAR and client JAR 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 the essence of this sample is to illustrate a module based registration, we'll focus only on the EJB JAR module i.e. pkgingCAppEjb.jar. Deploying this file is very similar to deploying an ear file, except that the deployer must be told that the type is an ejb. 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/pkgingC/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/pkgingC/

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

    sjsas_install_dir/samples/transactions/ejb/cmt/bank

  3. Execute the following:

    asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> -type ejb pkgingCAppEjb.jar

The deployment process involves the following operations:

  • 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 repository

    • Registers the module pkgingCAppEJB 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>

    You will see the pkgingCAppEJB as one of the listed modules.

  • 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

  1. Open the EJB JAR file i.e. pkgingCAppEjb.jar.

  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 JAR 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 > EJB Modules

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

  9. Select Deploy.



Running the Sample Application

A pre-requisite for running the remote client is that, the EJB module must first be deployed in an application server. See the Deploying the Sample Application section for details. Also, make sure that the PATH and CLASSPATH variables are set for the remote host and they refer to appropriate JDK. Running the remote client can be achieved through these following simple steps:

  1. Setup a staging directory for the client.

    Create a staging directory on a remote system, from where the client can be run. For example:

    • on UNIX, use $HOME/rmi-client/

    • on Windows, use C:\rmi-client\

      or

      D:\rmi-client\

  2. Copy the necessary JAR files to the remote host.

    Copy the following files from the server host and keep them in the staging directory. The files needed to run this client are:

    • pkgingCAppClient.jar

      This archive contains the client class file(s) and can be found at <sjsas_install_dir>/samples/packaging/pkgingC/assemble/client

    • pkgingCAppEjbClient.jar

      This contains the stubs, remote and home interface for the bean to be invoked remotely. Deployer generates this file while deploying the EJB module and copies it to this location. This can be found at <sjsas_install_dir>/samples/packaging/pkgingC/assemble/client

    • appserv-ext.jar

      This archive contains, all java classes to create a runtime environment and can be found at <sjsas_install_dir>/lib.

  3. Set the CLASSPATH for running the client.

    Open a command prompt in windows or a terminal in an UNIX system. Go to the staging directory.

    • In windows:

      set CLASSPATH=.;appserv-ext.jar;pkgingCAppEjbClient.jar;pkgingCAppClient.jar

    • In UNIX, depending on your shell, set the CLASSPATH to:

      .:appserv-ext.jar:pkgingCAppEjbClient.jar:pkgingCAppClient.jar

  4. Execute the Java Application Client.

    From the staging directory, execute the following command:

    java samples.packaging.pkgingC.client.ModuleClient <hostname> <port>

    Where <hostname> is the host name of the application server and <port> is the IIOP port number of the RMI-IIOP bridge. You may have to use JavaTM 1.4 to run this sample.

The application should generate the following messages (these are the values returned from the ModuleLibraryEJB):

Doing a JNDI lookup on ejb/SunONE.pkging.pkgingCEJB.ModuleLibrary

2 raised to the power of 3 is 8.0



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/pkgingC/javadocs/index.html


Troubleshooting



  • 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.



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

Last Updated August 13, 2002