BEA Logo BEA WebLogic Server Release 5.0

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

WebLogic Server Examples Guide

This document describes the various resources provided with the code examples shipped with BEA WebLogic ServerTM. For a listing of the examples and instructions, see the WebLogic Server Examples Index.
Introduction
Where Do I Start?
Setting Up Your Environment for Building and Running the Examples
The setExamplesEnv Script
What setExamplesEnv Does
Setting Your Environment for Type 2 JDBC Drivers
Example Build Scripts
Starting WebLogic Server with the Examples Configuration
The Examples Web Application
The Administration Console
Troubleshooting

Top of the page

Introduction

The examples contained in the samples/examples directory of the WebLogic Server distribution demonstrate a variety of features using WebLogic Server. Resources are provided to help you build, configure, and run each of the examples. These resources include:
  • Source files for server-side objects and client applications that demonstrate various programming tasks. The source files are located in the samples/examples directory.
  • Step-by-step instructions for building, configuring, and running each example. The instructions for each example are included in the directory that contains the associated source files.
  • A configuration file containing the configuration attributes for all of the examples. This configuration file, config.xml, is located in the config/examples directory of the WebLogic Server distribution.
  • A shell script for starting the server with the examples configuration. The startExamplesServer script ( .cmd for Windows NT/2000 installations or .sh for UNIX installations) is located in the config/examples directory.
  • A shell script for setting up your environment for building and running the examples. The setExamplesEnv script ( .cmd for Windows NT/2000 installations or .sh for UNIX installations) is located in the config/examples directory.
  • The config/examples/applications directory. This directory is used to store application archives ( .ear, .war, and .jar files) that are created when you build the examples.
  • The config/examples/clientclasses and config/examples/serverclasses directories. These directories are used to store classes required by the example clients and server-side objects respectively.
  • An evaluation copy of the Cloudscape DBMS located in the samples/eval/cloudscape directory. For more information see Using the Cloudscape Database with WebLogic Server.

Top of the page

Where do I start?

Begin by checking out the WebLogic Server Examples Index. The examples are organized by the API they demonstrate. Each example contains step-by-step instructions for building, configuring, and running the example. Many of the examples refer to back to this document for instructions on using the various resources included with the examples.

Top of the page

Setting Up Your Environment for Building and Running the Examples

When developing in Java, make sure that you have a controlled development environment. To avoid class conflicts and other problems that can be difficult to diagnose, you need to be aware of all of the environment settings that you use during development.

The CLASSPATH environment variable is very important as it is used by the java and javac commands to locate the Java classes that are required to run applications and compile source files. It is imperative that CLASSPATH contains the appropriate classes for compiling and running your applications.

This section discusses the use of the setExamplesEnv shell script to ensure that CLASSPATH and other environment variables are set properly and consistently for your development shell. A development shell is a command-line shell that you create for the purpose of compiling and running the examples shipped with WebLogic or for your own development. To be certain that this shell has the appropriate environment variable settings, run the setEnv script within the shell.

The setExamplesEnv Script

A script for setting up your development shell is included in the config/examples directory of your WebLogic distribution. There are two versions of the script. The one that you have will depend on which platform you have installed WebLogic Server:

setExamplesEnv.sh For a UNIX bourne shell. Because of the differences between UNIX shells, this script is supported on a bourne shell on UNIX only.
setExamplesEnv.cmd For Windows NT/2000. This script is to be run in a DOS command shell.

Running the script will set up environment variables for compiling and running the examples. To run the script, cd to the config/examples directory and execute the command:

  $ setExamplesEnv.cmd
on Windows NT/2000 or:
  $ . setExamplesEnv.sh
in a UNIX bourne shell. The ". " ensures that the variables set by setExamplesEnv are retained by the command shell after the script is run.

What setExamplesEnv does

setExamplesEnv sets the following environment variables in your development shell:
  • CLASSPATH -- contains all of the classes required to compile and run the examples
  • CLIENT_CLASSES -- points to the directory used to store client classes
  • SERVER_CLASSES -- points to directory used to store server-side classes
  • EX_WEBAPP_CLASSES -- points to the directory used to store classes used by the Examples Web Application
  • PATH -- appends the JDK and WebLogic bin directories

CLASSPATH

setExamplesEnv sets CLASSPATH in your development shell to include all of the classes necessary to compile and run the examples.
  • /weblogic/lib/weblogic.jar
  • /weblogic/lib/weblogic_sp.jar
  • /weblogic/config/examples/clientclasses
  • /weblogic/config/examples/serverclasses
  • /weblogic/config/examples/applications/examplesWebApp/WEB-INF/classes
where weblogic is the directory in which WebLogic is installed.

The script overwrites anything that is currently in CLASSPATH. If you would like to run other Java applications or tools from within your development shell, you must edit the set CLASSPATH command in the setExamplesEnv script to include any classes that these applications may require.

Target Variables

setExamplesEnv sets three target variables: CLIENT_CLASSES, SERVER_CLASSES, and EX_WEBAPP_CLASSES. These variables point to directory locations and can be used in conjunction with the -d option of the javac command to place the resulting compiled class in the appropriate directory.

Under the /config/examples directory in the WebLogic distribution, you will find directories intended for storing the classes generated when you build the examples shipped with WebLogic. These directories are:

  • /clientclasses -- for classes required by client applications
  • /serverclasses -- for classes required by server-side objects
  • /applications -- for application archives created when you build the examples
  • /applications/examplesWebApp/WEB-INF/classes -- for classes required by the Examples Web Application

The syntax for accessing environment variables is different between Windows NT/2000 and UNIX. For Windows NT/2000, variables are accessed by bracketing the variable name with "%" characters as shown below:

  $ javac -d %CLIENT_CLASSES% Client.java
For UNIX, variables are accessed by preceding the variable name with the "$" character as shown below:
  $ javac -d $CLIENT_CLASSES Client.java
Both of the commands above result in the compiled class being placed in the config/examples/clientclasses directory of the WebLogic distribution.

Setting Your Environment for Type 2 JDBC Drivers

Using a WebLogic Type 2 JDBC driver as a client requires an additional entry to your PATH variable. For instructions on setting your PATH (Windows NT/2000) or load library path (UNIX), see Installing WebLogic jDriver for Oracle.

If you will be using a Type 2 JDBC driver in a three-tier architecture, also modify the PATH (as described above) you use to start WebLogic Server.

Top of the page

Example Build Scripts

For your convenience, many of the examples are shipped with a build script that performs the steps required to compile the example. Build scripts are shipped in the directory that contains the source code of the example. For Windows NT/2000, build scripts are named build.cmd and can be executed by changing to the directory containing the build script and running the command:
  $ build
On UNIX, build scripts are named build.sh and can be executed in a bourne shell by changing to the directory containing the build script and running the command:
  $ sh build.sh

Top of the page

Starting WebLogic Server with the Examples Configuration

Using Shell Scripts

A configuration file containing the configuration attributes for all of the examples is located at config/examples/config.xml in the WebLogic Server distribution. The startExamplesServer shell script ( .cmd for Windows NT/2000 or .sh for UNIX bourne shell) set up the proper CLASSPATH for the server and will load the examples configuration file by setting the weblogic.Domain property to "examples". These shell scripts are located in the config/examples directory. To run these scripts, cd to the config/examples directory and execute the command:
  $ startExamplesServer.cmd
on Windows NT/2000 or:
  $ sh startExamplesServer.sh
in a UNIX bourne shell.

The server will start under the "system" identity. The password.ini file located in the config/examples directory contains the password for the system indentity, "examplesPassword", and will be automatically read by the server when it boots. If the password.ini file is removed from this directory, you will be prompted for a password when booting the server. If prompted, enter "examplesPassword".

Using the Windows Start Menu

On Windows NT/2000, you can also start the WebLogic Server with the examples configuration from the Windows Start Menu.
  1. Click on the Windows Start Menu
  2. Select Programs
  3. Select the WebLogic Server 6.0 program group
  4. Select the Examples submenu
  5. Select Start Examples Server

Top of the page

The Examples Web Application

Any example that uses servlets, JSPs, or Applets running in a browser must be deployed as a Web Application. For convenience, a single Web Application -- the Examples Web Application -- will be configured to deploy these examples. The Examples Web Application directory hierarchy can be found expanded in the config/examples/applications/examplesWebApp directory in the WebLogic distribution and will be preconfigured to work with the servlets and JSPs included in the examples. To verify that the Examples Web Application has been deployed on your server:
  1. Start the WebLogic Server with the examples configuration.
  2. Bring up the Administration Console in a browser.
  3. Click to expand the Deployments node in the left-hand pane.
  4. Click to expand the Web Applications node in the left-hand pane.
  5. Select the examplesWebApp node.
  6. Select the Targets tab in the right-hand pane to display the Available and Chosen targets.
  7. Verify that the examplesServer target appears in the Chosen column.

Top of the page

The Administration Console

When working with the examples, you will often be required to use the Administration Console to configure the server for the example. To work with the Administration Console, start WebLogic Server, then bring up the Administration Console in your browser with the URL:
http://hostname:port/console
where:
hostname
Host name of the WebLogic Server.
port
Port where the WebLogic Server is listening for connections.
Top of the page

Troubleshooting

Receive a "Page cannot be displayed" or a "Error 404 - Not found" error when attempting to hit the server with a browser.

This can happen, if you're browser is set up to access all URLs through a proxy server. If the machine running WebLogic Server is not registered with the proxy server, you will receive a URL failure from your browser. To fix this, you can either configure your browser to either not use the proxy server or to not go through the proxy server accessing an address that begins with the name of the machine running WebLogic Server.

 

Copyright © 2000 BEA Systems, Inc. All rights reserved.
Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
Last updated 09/29/1999