Sun Java System logo     
JNDI URL Sample Application



JNDI URL Sample Application


This document describes how to utilize the JNDI URL sample application in conjunction with Sun Java (tm) System Application Server 7.

This sample application document contains the following sections:



Overview

Note The URL specified under sun-ejb-jar.xml assumes the http server port of Sun Java (tm) System application server installation to be 1024. If the port is other than 1024, you must modify sun-ejb.jar.xml before compiling and deploying the sample.


The JNDI URL sample application demonstrates the usage of the JNDI resource to connect to a URL. The application uses an EJB for displaying the contents of a web page by connecting to its URL. The jndi-name element of EJB in sun-ejb-jar.xml specifies a target URL. The EJB is invoked by a client class.



Compiling and Assembling the Application



This section contains instructions to build and assemble the JNDI URL sample application using a Command Line Interface (CLI).

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

  1. Add <install_dir>/bin to your path.

  2. Go to <install_dir>/samples/jndi/url/src/.

    Execute the command asant

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

  4. Deploy the application.

    After you have re-created the sample application from scratch, you may proceed to Deploying the Sample Application. Step 5 is optional.

  5. Clean the application project area (optional).

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

    Now you are ready to use this ear file for deployment.

    Note The URL specified under sun-ejb-jar.xml assumes the http server port of Sun Java (tm) System application server installation to be 1024. If the port is other than 1024, you must modify sun-ejb.jar.xml before compiling and deploying the sample.





Deploying the Sample Application

In this section, you will learn how to deploy the JNDI URL sample application.

Select one of the following approaches to deploying the application:

  • Command Line-based Deployment describes how to manually register the application in Sun Java (tm) System Application Server using a Command Line Interface (CLI). This is the fastest means of deploying the sample application.

  • GUI-based Deployment describes how to use the Sun Java (tm) System Application Server Deployment Tool to import and deploy the sample application.

Command Line-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.

The pre-built jndi-url.ear file is a Enterprise Archive file that contains the JAR file of the application. Within the JAR file resides the XML deployment descriptor files, application class files, and other content required by the application.

Deploying the pre-built jndi-url.ear file is simple. Deploy either using asant command or using asadmin command.

Using the asant script

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

    <install_dir>/samples/jndi/url/src

  2. Run asant using deploy task. For example:

    %asant deploy

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 JAR file

    • Explodes the bits into repository

    • Registers the J2EE application "jndi-url" by updating server.xml

    • Creates the jndi resource required for running this application

    • Reconfigures the application server instance for the newly added resource.

If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.

GUI-based Deployment

Since a pre-built Enterprise Archive (EAR) file for the sample application is included with the application server, you may use the Sun Java (tm) System Application Server Administration Tool to quickly read in the .ear file and deploy it to the application server.

  1. From your web browser, access the Sun Java (tm) System Application Server by executing the following:

    <install_dir>/domains/domain1/admin-server/bin/startserv

  2. Open the EAR file

  3. Navigate to the browser based admin server page. For example:

    http://<server-host>:<admin-port>/index.html

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

  5. In the left pane, navigate the tree by clicking on the following:

    App Server Instances>server1>Applications>Enterprise Apps

  6. In the right hand pane, click on Deploy button to deploy an application.

    Select the file (from disk) to be deployed (jndi-url.ear) and Click OK.

  7. You will be prompted for the application name.

    Type jndi-url and Click OK.

If the deployment processes correctly, you will see the original panel displaying the JNDI URL application as deployed.


Verifying Deployment

As an optional step, you can use the Sun Java (tm) System Application Server Administration Tool to verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.

To verify the registration of the application, do the following:

Execute the command asadmin list-components 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>.


Note You may also verify by navigating the Administration Tool GUI to:

App Server Instances>server1>Applications>Enterprise Apps.

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





Running the Sample Application



The URL connection factories do not require any resources to be created in server.xml. The application is run by running the client class, which invokes the Ejb.

To run the JNDI URL sample application, do the following:

  1. Go to the following directory: <install-dir>/domains/domain1/<server-instance>/applications/j2ee-apps/jndi-url_1/

  2. Enter the following command:

    <install_dir>/bin/appclient -client jndi-urlClient.jar -name jndi-urlClient -textauth

    The contents of the index.html file that resides in <install_dir>/samples/ will be displayed.


Generating javadocs

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

To generate javadocs, run one of the following commands:

asant javadocs

or

asant all

After javadocs are generated, you may access them at <install_dir>/samples/jndi/url/javadocs/index.html.



Troubleshooting



  • The URL specified under sun-ejb-jar.xm l assumes the http server port of Sun Java (tm) System application server installation to be 1024. If the port is other than 1024, you must modify sun-ejb.jar.xml before compiling and deploying the sample.

  • Please make sure that you run asant undeploy before redeploying this sample. This will ensure that all modules are undeployed and the resources are disabled.

  • Although the ear, context-root and servlet alias names in this sample are all "jndi-url", 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 application after changing the context-root (in application.xml), the and ear names (in the build.xml). Redeploy and test the sample to confirm thees changes.

  • If you encounter problems when running the application, review the log files at <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 July 11, 2002