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
Quick Start
The Examples Web Application
Setting Up Your Environment for Building and Running the Examples
The setExamplesEnv Script
What setExamplesEnv Does
Setting Your Environment for Type 2 JDBC Drivers
Building the Examples
Starting WebLogic Server with the Examples Configuration
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

Quick Start

This section provides quick instructions for building and running the examples in the samples\examples directory. The steps are explained in more detail in the following sections.

If you are using a UNIX operating system, substitute a forward slash (/) for the backward slash (\) in the commands.

To build and run an example:

  • Move to the weblogic\samples\examples directory.
  • Choose an example.
  • Open the package-summary.html file in the example directory.
  • Open a command window.
  • Move to weblogic\config\examples.
  • Set up your development shell: setExamplesEnv (on Windows) or . setExamplesEnv.sh (on UNIX Bourne shell). Do the next four steps in the same command window.
  • Move up in the directory structure: cd ..\..
  • Move to the directory of the example you want to start: cd samples\examples\directoryName.
  • Make sure the directory has a build.xml file.
  • Enter ant to build the example.
  • Open a new command window.
  • Move to config\examples.
  • Start the WebLogic Server: startExamplesServer (on Windows) or . startExamplesServer.sh (on UNIX Bourne shell).
  • Enter the password you chose when you installed the WebLogic Server.
  • If the example uses JSP pages, servlets, or applets running in a Web browser, follow the instructions in the next section.
  • Otherwise, follow the instructions in the example's package-summary.html file to start the example.
Top of the page

For Web Examples

Any example that uses servlets, JSPs, or Applets running in a browser must be deployed as a Web Application. To do so, follow these steps:
  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

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

Building the Examples

For your convenience, many of the examples are shipped with a build script that performs the steps required to compile the example. These build scripts, which share the common name build.xml, are shipped in the directories that contain the source code of the examples.

  • To execute a build script, change to the directory that contains the build script and run the following command:
      $ ant

The examples.properties File

The ant utility uses the examples.properties file to set system properties when it runs. By default, when you download the WebLogic Server, examples.properties looks like this:

     #choose classic, modern, jikes, or jvc
     JAVAC=modern
     WL_HOME=C:/weblogic61/wlserver6.1
     CLIENT_CLASSES=${WL_HOME}/config/examples/clientclasses
     SERVER_CLASSES=${WL_HOME}/config/examples/serverclasses
     EX_WEBAPP_CLASSES=${WL_HOME}/config/examples/applications/examplesWebApp/WEB-INF/classes
     APPLICATIONS=${WL_HOME}/config/examples/applications
     XMLRegistry=${WL_HOME}/config/examples/xml/registries/examplesXMLRegistry

You can edit examples.properties with a text editor, if you need to change any system properties. You might need to do this, for example, if you have changed a directory location in your WebLogic home.

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. You should enter the password that was chosen interactively when the server was installed.

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

Running in Development or Production Mode

The WebLogic Server has three applications domains:

	weblogic\config\examples
	weblogic\config\mydomain
	weblogic\config\petstore

Each domain can be set to either development or production mode. The mode determines whether applications stored in any of these domains are deployed.

To deploy an application, you need to package it into a JAR, WAR, or EAR file and move it to the applications directory within one of the domains. The examples provided with the WebLogic Server have build scripts that package the application and store it in a domain for you. An application in one of the domains is deployed if

  • The domain is in development mode and you register the application in the domain's config.xml file, or
  • Regardless of the domain's mode, you store its JAR, WAR, or EAR file in the applications directory, and then start the server. This technique is called dynamic deployment.
To make sure an application is not deployed:
  • Change the domain to production mode
  • Do not list the application in config.xml
  • Move its JAR, WAR, or EAR file out of the applications directory.

To deploy the examples in samples\examples, make sure that the examples domain is in development mode. It's set to development mode by default, when you download the WebLogic Server. If you need to change a domain's mode from production to development, do this:

  • Use a text editor to open the start script for your domain.
  • Edit the line that begins set STARTMODE=. True is for production mode, and false is for development mode.

Initially, when you download the WebLogic Server, the domains are set with these modes:

  • weblogic\config\examples - development mode
  • weblogic\config\mydomain - production mode
  • weblogic\config\petstore - production mode
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 © 2001 BEA Systems, Inc. All rights reserved.
Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
Last updated Release 6.1 SP01