Examples Index | Ant | PointBase | Run Examples with PointBase | Samples and Tutorials

 

WebLogic Server Examples Guide

 

 

 

Contents

Introduction
Basic Steps for Using the Examples
The Examples Web Application
More About Setting Up Your Environment
Setting Up Your Environment for Type 2 Drivers
More About Building Examples and examples.properties
The Examples Database
Examples Passwords and Server Start Up
Running Examples from Another Directory
Running the Examples Server Using the JRockit JVM
Using Development or Production Mode To Run Examples
Setting up WebLogic Clusters for the Examples
Troubleshooting

 

 

Introduction

To pull up the examples, go to:

http://www.setgetweb.com:7001/examplesWebApp/index.jsp *

Examples can be found under:

# cd $WL_HOME/samples/server/examples
# pwd
/usr/local/bea/weblogic81/samples/server/examples
# ls
build  src 

Source files are separated from the domain files.

# cd $WL_HOME/samples/server/examples/src
# ls
allclasses-frame.html    examples.properties    package-list      black.css
allclasses-noframe.html  index.html             packages.html     constant-values.html     
overview-frame.html      resources/             examples/         overview-summary.html     
serialized-form.html

Included with each WebLogic Server example is a package-summary.html file. This file contains all the information you will need to run that particular example, from building, to configuring, to running--and anything else you may need to know along the way.

The $WL_HOME/samples/domains/examples directory contains your examples domain; it contains your applications and the XML configuration files that define how your applications and WebLogic Server will behave, as well as startup and environment scripts.

The $WL_HOME/samples/server/examples/build directory contains client and server classes required by the examples, and PointBase.

The WL_HOME/common/eval directory contains PointBase, a demonstration database that the examples are configured to use. It also contains the PointBase documentation and scripts that start, stop, and open the console for the PointBase database.

The sections below detail the general steps that you will have to take in order to run the examples. They also include tips, such as changing the port WebLogic listens on, running the examples from a new directory, and troubleshooting notes. If you are looking for further information or help on how the examples are set up, read on. If you are comfortable with WebLogic Server, go right to the overview-summary page that is in your $WL_HOME/samples/server/examples/src directory. This page has links to all the WebLogic examples.

 

 

Basic Steps for Using the Examples

These instructions describe the general tasks that need to be accomplished in order to run the WebLogic examples. The package-summary.html file for each example has all the documentation you need; this is a summary of the general steps you will take. Further along in this document it is explained in detail what exactly you are doing, and why.

 

 

Setting Up Your Environment     More Info

Before you can build and run the examples, you need to properly set up your development environment. This includes specifying the location of a JDK, determining where client and server classes are placed, setting the CLASSPATH, and having certain tools available. We have included a script that will properly set all these values:

  1. Open a command window.

  2. Move to the examples configuration directory:

    cd $WL_HOME/samples/domains/examples

  3. Enter:

    . setExamplesEnv.sh

 

 

 

Building an Example     More Info

Some examples run right from a browser when you boot up the server. These are the 'out-of-the-box' examples and will pop up in a window when you start the examples domain with WebLogic Server. As in the real development world, the rest of the WebLogic examples start off as java source files. They must be compiled into class files, or 'built', first. We provide ant scripts in XML files; running these scripts will build the corresponding example. Here are the general steps:

  1. Move to the directory of the example you want to use:

    cd $WL_HOME/samples/examples/src/examples/directoryName

  2. If the package-summary.html file for your example instructs you to do so, edit...

    $WL_HOME/samples/server/examples/src/examples.properties

    The Ant task uses this file to set system properties.

  3. There will be a build.xml file inside your examples directory, this is the script that builds the example. Enter ant to build the example; it will run the script in the build.xml file.

 

 

 

Starting the Examples Server

To start the examples server go to:

  1. cd $WL_HOME/samples/domains/examples

  2. sh ./startExamplesServer.sh

  3. The console should now be available:

    http://www.setgetweb.com:7001/console

Note that by default, the examples server uses the port 7001 to listen for incoming connections. The MedRec server also uses the same listen port by default, which means that you cannot run both domains at the same time without changing one of the listen ports. If you want to run both domains at the same time, use the WebLogic Server Administration Console to change the listen port of the examples server to something other than 7001, then restart it. You will now be able to start the MedRec server using its default listen port at the same that you run the examples server.

 

 

Starting the WebLogic Server Console

You often need to use the WebLogic Server Console to set up an example before you run it.

To start the Console:

  1. Start the examples server.
  2. Open a browser and point go to http://your.domain.com:7001/console

  3. Enter weblogic for both the system name and password.

 

 

Running the Examples

The build scripts included with each example contain a run command. To run an example, go to the directory where the example is located and type:

ant run

This will execute the run target that starts the example; to view the command, go into the build.xml file and look for the section with the target called 'run.' This command may use variables; in some cases you may need to edit the build.xml before you run the script. If you are having problems with an example, it is a good idea to check the run target. You may need to set a port, parameter, or some other information that is unique to your setup. Also, some examples require that you modify this command, if, for instance, there are multiple ways to run the example. In all of the above cases, the example's package-summary.html will contain instructions telling you how to modify the command.

 

 

 

The Examples Web Application

If an example uses servlets, JSP files, or applets, you can deploy it as a Web application. We have taken many of these examples and put them into one Web Application called examplesWebApp, located in:

$WL_HOME/samples/server/examples/build/examplesWebApp

Each example that requires it contains specific instruction on using the examplesWebApp.

Follow these steps if you wish to verify that the examplesWebApp has been deployed:

  1. Start the WebLogic Server Administration Console.
  2. Expand the Deployments node in the left pane.
  3. Expand the Web Applications Modules node in the left pane.
  4. Select the examplesWebApp node.
  5. Select the Targets tab in the right pane.
  6. Verify that the examplesServer target is checked.
  7. If the examplesServer is not targeted, mark the checkbox next to examplesServer and click 'Apply.'

 

 

 

More About Setting Up Your Environment

The setExamplesEnv.sh script, located at...

$WL_HOME/samples/domains/examples
...sets certain environment variables:

$WL_HOME/samples Where the examples were installed
$APPLICATIONS Application archives created when you build the examples
$CLIENT_CLASSES Classes that the examples client applications require
$SERVER_CLASSES Classes that the examples server-side classes require
$COMMON_CLASSES Utility classes used by the examples, and PointBase
$EX_WEBAPP_CLASSES Classes required by the Examples Web Application used by the WebLogic Examples server
$WEBSERVICES_JAR Files used by WebLogic Server's web services implementation

These variables point to directory locations under either...

$WL_HOME/samples/domains/examples

or

$WL_HOME/samples/server/examples/build

The setExamplesEnv.sh script also sets the CLASSPATH variable in your development shell to include certain classes that you need as you build and run the examples. Since these classes could be anywhere on your system or network, you need to specify where to find the classes you are trying to run. The contents of your CLASSPATH will vary depending on the system you are running and how your directories are organized. Running the setExamplesEnv.sh script sets the CLASSPATH correctly for you when you are using the WebLogic Examples. Specifically, here are the jar files and directories that setExamplesEnv.sh puts in your CLASSPATH:


    $BEA_HOME/jdk131/lib/tools.jar
    $WL_HOME/server/lib/weblogic_sp.jar
    $WL_HOME/server/lib/weblogic.jar
    $WL_HOME/server/lib/ojdbc14.jar
    $WL_HOME/server/lib/webservices.jar
    $WL_HOME/samples/samples/server/examples/build/clientclasses
    $WL_HOME/samples/samples/server/examples/build/serverclasses
    $WL_HOME/samples/samples/server/examples/build/examplesWebApp/WEB-INF/classes
    $WL_HOME/common/eval/pointbase/lib/pbclient44.jar
    $WL_HOME/common/eval/pointbase/lib/pbserver44.jar

When you run setExamplesEnv, it overwrites anything that is currently in CLASSPATH. If you want to run other Java applications or tools from within your development shell, you must edit the set CLASSPATH command in the setExamplesEnv.sh script to include any classes those applications may require.

 

 

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 PATH, see Installing WebLogic jDriver for Oracle.

If you want to use a Type 2 JDBC driver in a three-tier architecture, also modify the PATH variable you use to start WebLogic Server. The WebLogic Server Examples Database Guide has instructions for setting up an Oracle database for the examples.

 

 

More About Building Examples and the examples.properties file

Each example has an Ant task that builds the example. Each Ant task is named build.xml and is located in the example's source code directory.

The Ant task uses the examples.properties file to set system properties when it runs. The examples.properties file is located at

$WL_HOME/samples/server/examples/src

You can use a text editor to edit examples.properties if you need to. For example, if you have changed a directory location in your WebLogic home directory, are running the examples using an Oracle database, or have set your WebLogic Server to listen on a port other than 7001.

If you changed the port number when you installed WebLogic Server, rather than accepting the default port of 7001, you will need to edit the examples.properties file to change it there as well.

 

 

The Examples Database

The examples use a demonstration database: Pointbase 4.3. PointBase Server is a pure Java RDBMS that is included with WebLogic Server. Its purpose is to allow you to run code examples with a functional database server. For more information on PointBase and the examples see our PointBase page. The examples can also be run with Oracle as the database; for instructions on how to do so, see the database setup page.

 

 

Examples Passwords and Server Startup

The examples domain uses weblogic/weblogic as its username/password combination. The startExamplesServer.sh scripts set these values as:

set WLS_db.user=weblogic
set WLS_PW=weblogic

This script sets some additional values for initial server startup, and then calls the startWebLogic script located in your WL_HOME/server/bin directory. This script is what actually starts the server. In there the following parameters are set:

-Dweblogic.management.username=$WLS_db.user
-Dweblogic.management.password=$WLS_PW

If you ever need to change your username/password for the examples domain, you will have to change the values in the examples startExampleServer script.

In the default configuration the server will start up without prompting for a password. If you wish to reenable start-up security, simply remove the username/password values from the startWebLogic script; the server will then prompt for a username/password when you start it.

 

 

Running Examples from Another Directory

You may want to install, build, and run the examples from a location other than where they were installed. This is useful if several developers are working with one WebLogic Server installation, or if you simply want to become accustomed to developing in a directory of your own choosing. It is also a best practice; keeping your domains in a separate location apart from you WebLogic installation helps keep potential conflicts to a minimum, and means you won't have multiple developers altering files that are inside WebLogic's own directories.

These instructions show you an example of how to set up your own directory structure to build and run examples from a location you choose using Windows Explorer. The general idea behind these steps are two-fold; copy the directory structure with the source files of the examples to your own location and also inform WebLogic Server where your new domain resides. WebLogic will know where your new domain is located as long as you modify the following files as instructed below: examples.properties, startExamplesServer.sh, and config.xml files.

Here is an example:

  1. Create subdirectories:

    mkdir /usr/mysamples
    mkdir /usr/mysamples/server
    mkdir /usr/mysamples/server/config
    mkdir /usr/mysamples/server/src
    mkdir /usr/mysamples/server/stage

  2. Copy directories and files:

    cp -r $SAMPLES_HOME/server/examples/src/examples    /usr/mysamples/server/examples/src
    cp    $SAMPLES_HOME/server/examples/src/examples.properties    /usr/mysamples/server/examples/src
    cp -r $SAMPLES_HOME/server/examples/build    /usr/mysamples/server/examples
    cp -r $SAMPLES_HOME/domains/examples    /usr/mysamples/domains

  3. Customize examples.properties:

  4. cd /usr/mysamples/domains/examples

  5. Edit startExamplesServer.sh and set the $SAMPLES_HOME to the location you've chosen for the examples:

  6. In the same directory, open the config.xml file with a text editor. Several of the examples are dynamically deployed and have entries written to the config.xml on start up. If you have run the examples server at least once, you will have to remove the following entries from the config.xml in your myexamples/home/server/config directory, make sure to not to delete the three application entries that are not in this list (the security, default Web Application, and examples Web Application):

    <Application Deployed="true"
        Name="_appsdir_ejb20_basic_beanManaged_ear"
        Path="/usr/myexamples/domains/examples/applications/ejb20_basic_beanManaged.ear"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="ejb20_basic_beanManaged.jar"
            Targets="examplesServer" URI="ejb20_basic_beanManaged.jar"/>
    </Application>
    <Application Deployed="true"
        Name="_appsdir_ejb20_basic_containerManaged_ear"
    Path="/usr/myexamples/domains/examples/applications/ejb20_basic_containerManaged.ear"
    StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="ejb20_basic_containerManaged.jar"
            Targets="examplesServer" URI="ejb20_basic_containerManaged.jar"/>
    </Application>
    <Application Deployed="true"
        Name="_appsdir_ejb20_basic_statefulSession_ear"
        Path="/usr/myexamples/domains/examples/applications/ejb20_basic_statefulSession.ear"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="ejb20_basic_statefulSession.jar"
            Targets="examplesServer" URI="ejb20_basic_statefulSession.jar"/>
    </Application>
    <Application Deployed="true"
        Name="_appsdir_ejb20_basic_statelessSession_ear"
        Path="/usr/myexamples/domains/examples/applications/ejb20_basic_statelessSession.ear"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="ejb20_basic_statelessSession.jar"
            Targets="examplesServer" URI="ejb20_basic_statelessSession.jar"/>
    </Application>
    <Application Deployed="true" Name="_appsdir_ejb20_homemethods_ear"
        Path="/usr/myexamples/domains/examples/applications/ejb20_homemethods.ear"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="ejb20_homemethods.jar"
            Targets="examplesServer" URI="ejb20_homemethods.jar"/>
    </Application>
    <Application Deployed="true" Name="_appsdir_ejb20_message_ear"
        Path="/usr/myexamples/domains/examples/applications/ejb20_message.ear"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="ejb20_message.jar" Targets="examplesServer" URI="ejb20_message.jar"/>
    </Application>
    <Application Deployed="true" Name="_appsdir_jdbc_oracle_ext_ear"
        Path="/usr/myexamples/domains/examples/applications/jdbc_oracle_ext.ear"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="jdbc_oracle_ext.jar"
            Targets="examplesServer" URI="jdbc_oracle_ext.jar"/>
    </Application>
    <Application Deployed="true" Name="_appsdir_jms_messageformat_jar"
        Path="/usr/myexamples/domains/examples/applications"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="jms_messageformat" Targets="examplesServer" URI="jms_messageformat.jar"/>
    </Application>
    <Application Deployed="true" Name="_appsdir_jta_ejb_jmsjdbc_jar"
        Path="/usr/myexamples/domains/examples/applications"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="jta_ejb_jmsjdbc" 
                      Targets="examplesServer" URI="jta_ejb_jmsjdbc.jar"/>
    </Application>
    <Application Deployed="true" Name="_appsdir_webservices_trader_ear"
        Path="/usr/myexamples/domains/examples/applications/webservices_trader.ear"
        StagedTar<gets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="trader.jar" 
                       Targets="examplesServer" URI="trader.jar"/>
        <WebServiceComponent Name="trader_service.war"
                       Targets="examplesServer" URI="trader_service.war"/>
    </Application>
    <Application Deployed="true" Name="_appsdir_xml_xslt_content_ear"
        Path="/usr/myexamples/domains/examples/applications/xml_xslt_content.ear"
        StagedTargets="examplesServer" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="xml_xslt_content.jar"
                       Targets="examplesServer" URI="xml_xslt_content.jar"/>
    </Application>
    

  7. Search for the three <application> entries that are left. Change the directory name in the PATH attribute to /usr/mysamples or the correct directory under /usr/mysamples:


    <Application
        Deployed="true"
        Name="mainWebApp"
        Path="/usr/myexamples/domains/examples/applications"
    >


    <Application
        Deployed="true"
        Name="security"
        Path="/usr/myexamples/server/examples/src/examples/webapp">

    <Application
        Deployed="true"
        Name="examplesWebApp"
        Path="/usr/myexamples/server/examples/build" TwoPhase="false">
         

    Do not change the values in the <server> element. In config.xml, leave those values alone.

  8. Save the config.xml file.

  9. Now, you can run the examples from the /usr/mysamples directory. Build and run the examples according the instructions in the example's documentation that you wish to run.

 

 

Running the Examples Server Using the JRockit JVM

The setExamplesEnv.sh script calls another script, WL_HOME/common/bin/commEnv, to set the default JVM used in your environment. If you want to run the examples server using the JRockit JVM, to edit the commEnv script:

  1. Open the WL_HOME/common/bin/commEnv.cmd or WL_HOME/common/bin/commEnv.sh (for Unix platforms) script in a text editor. Look for lines similar to:

    if [ "$1" != "USE_CURRENT_JAVA_HOME" ]; then
      # Set up JAVA HOME
      JAVA_HOME="/bea/jdk141_02"
      # Set up JAVA VENDOR, possible values are
      #BEA, HP, IBM, Sun ...
      JAVA_VENDOR=Sun
      # PRODUCTION_MODE, default to the development mode
      PRODUCTION_MODE=""
    fi

  2. Change the JAVA_HOME and JAVA_VENDOR variables to specify the JRockit JVM, as in:

    if [ "$1" != "USE_CURRENT_JAVA_HOME" ]; then
      # Set up JAVA HOME
      JAVA_HOME="/bea/jrockit81_141_02"
      # Set up JAVA VENDOR, possible values are
      #BEA, HP, IBM, Sun ...
      JAVA_VENDOR=BEA
      # PRODUCTION_MODE, default to the development mode
      PRODUCTION_MODE=""
    fi

  3. Set your environment according to the instructions in Basic Steps for Using the Examples.

 

 

Using Development or Production Mode To Run Examples

You can run the WebLogic Server examples in either Production or Development mode. In Development mode, applications stored in a domain are dynamically deployed, that is, deployed automatically when you start the server; in Production mode, this is not the case and deploy an application manually. For instructions on deploying applications, see the Deploying Applications chapter in the Administration Guide. By default, when you start the examples server, the examples domain is in development mode.

To change a domain's mode:

  1. Edit the start script for your domain:

    $WL_HOME/samples/domains/examples/startExamplesServer.sh

  2. Edit the line that begins set STARTMODE= to add the value True or False.

    ###
    ### Set Production Mode. When this is set to true, the server starts up in
    ### production mode. When set to false, the server starts up in development
    ### mode. If it is not set, it will default to false.
    set STARTMODE=

    True is for production mode, and false or no value is for development mode.

 

Clustering

Some of the examples demonstrate how to use WebLogic in clusters, also you can run any of the examples in a clustered environment. For information on clusters and how to set them up, read our Examples Cluster Guide. Also, check out our WebLogic Clustering Documentation.

 

Troubleshooting

  • The server starts with the error java.net.BindException - Address already in use.

    You can continue safely with this error. It means that the PointBase database has already been started by another process. If you see this error, simply disregard it.

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

    This can happen if your 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 configure your browser to not use the proxy server, or to not use the proxy server to access an address that begins with the name of the machine running WebLogic Server.