Skip navigation.

WebLogic Scripting Tool

  Previous Next vertical dots separating previous/next from contents/index/pdf Contents View as PDF   Get Adobe Reader

Using the WebLogic Scripting Tool

The following sections describe the WebLogic Scripting Tool:

 


What is the WebLogic Scripting Tool?

The WebLogic Scripting Tool (WLST) is a command-line scripting interface that system administrators and operators use to monitor and manage WebLogic Server instances and domains. The WLST scripting environment is based on the Java scripting interpreter, Jython. In addition to WebLogic scripting functions, you can use common features of interpreted languages, including local variables, conditional variables, and flow control statements. WebLogic Server developers and administrators can extend the WebLogic scripting language to suit their environmental needs by following the Jython language syntax. See http://www.jython.org.

What Does WLST Do?

WLST lets you perform the following tasks:

WLST functionality includes the capabilities of these WebLogic Server command-line utilities: the weblogic.Admin utility that you use to interrogate MBeans and configure a WebLogic Server instance (deprecated in this release of WebLogic Server), the wlconfig Ant task tool for making WebLogic Server configuration changes, and the weblogic.Deployer utility for deploying applications. For more information about these command-line utilities, see:

You can create, configure, and manage domains using WLST, command-line utilities, and the Administration Console interchangeably. The method that you choose depends on whether you prefer using a graphical or command-line interface, and whether you can automate your tasks by using a script. See Script Mode.

How Does WLST Work?

You can use the scripting tool online (connected to a running Administration Server or Managed Server instance) and offline (not connected to a running server). For information on WLST online and offline commands, see WLST Online and Offline Command Summary.

Using WLST Online

Online, WLST provides simplified access to Managed Beans (MBeans), Java objects that provide a management interface for an underlying resource that you can manage through JMX. WLST is a JMX client; all the tasks you can do using WLST online, can also be done programmatically using JMX.

For information on using JMX to manage WebLogic Server resources, see Developing Custom Management Utilities with JMX.

When WLST is connected to an Administration Server instance, the scripting tool lets you navigate and interrogate MBeans, and supply configuration data to the server. When WLST is connected to a Managed Server instance, its functionality is limited to browsing the MBean hierarchy.

While you cannot use WLST to change the values of MBeans on Managed Servers, it is possible to use the Management APIs to do so. BEA Systems recommends that you change only the values of configuration MBeans on the Administration Server. Changing the values of MBeans on Managed Servers can lead to an inconsistent domain configuration.

Using WLST Offline

Using WLST offline, you can create a new domain or update an existing domain without connecting to a running WebLogic Server—supporting the same functionality as the Configuration Wizard.

Offline, WLST only provides access to persisted configuration information. You can create new configuration information, and retrieve and change existing configuration information that is persisted in the domain configuration files (located in the config directory, for example, config.xml) or in a domain template JAR created using Template Builder.

Note: Because WLST offline enables you to access and update the configuration objects that appear in the configuration files only, if you wish to view and/or change attribute values for a configuration object that is not already persisted in the configuration files as an XML element, you must first create the configuration object.

 


Modes of Operation

WLST is a command-line interpreter that interprets commands either interactively, supplied one-at-a-time from a command prompt, or in batches, supplied in a file (script), or embedded in your Java code. The modes of operation represent methods for issuing WLST commands:

Interactive Mode

Interactive mode, in which you enter a command and view the response at a command-line prompt, is useful for learning the tool, prototyping command syntax, and verifying configuration options before building a script. Using WLST interactively is particularly useful for getting immediate feedback after making a critical configuration change. The WLST scripting shell maintains a persistent connection with an instance of WebLogic Server. Because a persistent connection is maintained throughout the user session, you can capture multiple steps that are performed against the server. See Recording User Interactions.

In addition, each command that you enter for a WebLogic Server instance uses the same connection that has already been established, eliminating the need for user re-authentication and a separate JVM to execute the command.

Script Mode

Scripts invoke a sequence of WLST commands without requiring your input, much like a shell script. Scripts contain WLST commands in a text file with a .py file extension, for example, filename.py. You use script files with the Jython commands for running scripts. See Running Scripts.

Using WLST scripts, you can:

In Listing 2-1, WLST connects to a running Administration Server instance, creates 10 Managed Servers and two clusters, and assigns the servers to a cluster.

Edit the script to contain the username, password, and URL of the Administration Server and start the server before running this script. See Running Scripts.

Listing 2-1 Creating a Clustered Domain

from java.util import *
from javax.management import *
import javax.management.Attribute
print 'starting the script .... '
connect('username','password','t3://localhost:7001')
clusters = "cluster1","cluster2"
ms1 = {'managed1':7701,'managed2':7702,'managed3':7703, 'managed4':7704, 'managed5':7705}
ms2 = {'managed6':7706,'managed7':7707,'managed8':7708, 'managed9':7709, 'managed10':7710}
clustHM = HashMap()
edit()
startEdit()
for c in clusters:
  print 'creating cluster '+c
  clu = create(c,'Cluster')
  clustHM.put(c,clu)
cd('..\..')
clus1 = clustHM.get(clusters[0]) 
clus2 = clustHM.get(clusters[1])
for m, lp in ms1.items():
  managedServer = create(m,'Server')
  print 'creating managed server '+m
  managedServer.setListenPort(lp)
  managedServer.setCluster(clus1)
for m1, lp1 in ms2.items():
  managedServer = create(m1,'Server')
  print 'creating managed server '+m1
  managedServer.setListenPort(lp1)
  managedServer.setCluster(clus2)
save()
activate(block="true")
disconnect()
print 'End of script ...'
exit()

Embedded Mode

In embedded mode, you instantiate an instance of the WLST interpreter in your Java code and use it to run WLST commands and scripts. All WLST commands and variables that you use in interactive and script mode can be run in embedded mode.

Listing 2-2 illustrates how to instantiate an instance of the WLST interpreter and use it to connect to a running server, create two servers, and assign them to clusters.

Listing 2-2 Running WLST From a Java Class

package wlst;
import java.util.*;
import weblogic.management.scripting.utils.WLSTInterpreter;
import org.python.util.InteractiveInterpreter;
/**
 * Simple embedded WLST example that will connect WLST to a running server,
 * create two servers, and assign them to a newly created cluster and exit.
 * <p>Title: EmbeddedWLST.java</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: BEA Systems</p>
 * @author Satya Ghattu (sghattu@bea.com)
 */
public class EmbeddedWLST 
{
  static InteractiveInterpreter interpreter = null;
  EmbeddedWLST() {
    interpreter = new WLSTInterpreter();
  }
private static void connect() {
    StringBuffer buffer = new StringBuffer();
    buffer.append("connect('weblogic','weblogic')");
    interpreter.exec(buffer.toString());
  }
private static void createServers() {
    StringBuffer buf = new StringBuffer();
    buf.append(startTransaction());
    buf.append("man1=create('msEmbedded1','Server')\n");
    buf.append("man2=create('msEmbedded2','Server')\n");
    buf.append("clus=create('clusterEmbedded','Cluster')\n");
    buf.append("man1.setListenPort(8001)\n");
    buf.append("man2.setListenPort(9001)\n");
    buf.append("man1.setCluster(clus)\n");
    buf.append("man2.setCluster(clus)\n");
    buf.append(endTransaction());
    buf.append("print `Script ran successfully ...' \n");
    interpreter.exec(buf.toString());
  }
private static String startTransaction() {
    StringBuffer buf = new StringBuffer();
    buf.append("edit()\n");
    buf.append("startEdit()\n");
    return buf.toString();
  }
private static String endTransaction() {
    StringBuffer buf = new StringBuffer();
    buf.append("save()\n");
    buf.append("activate(block='true')\n");
    return buf.toString();
  }
  public static void main(String[] args) {
    new EmbeddedWLST();
    connect();
    createServers();
  }
}

 


Main Steps for Using WLST

The following sections summarize the steps for setting up and using WLST:

Setting Up Your Environment

To set up your environment for WLST:

  1. Install and configure the WebLogic Server software, as described in the WebLogic Server Installation Guide.
  2. Add WebLogic Server classes to the CLASSPATH environment variable and WL_HOME\server\bin to the PATH environment variable, where WL_HOME refers to the top-level installation directory for WebLogic Server.
  3. You can use a WL_HOME\server\bin\setWLSEnv script to set both variables.

    On Windows, a shortcut on the Start menu sets the environment variables and invokes WLST (Tools—>WebLogic Scripting Tool).

Invoking WLST

Note: When invoking WLST from an Ant script, it is recommended that you fork a new JVM by specifying fork="true". This will ensure a clean environment and prevent the WLST exit command, which calls System.exit(0), from exiting the Ant script.

To invoke WLST:

  1. If you will be connecting to a WebLogic Server instance through an SSL listen port on a server that is using the demonstration SSL keys and certificates, invoke WLST using the following command:

java -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=DemoTrust weblogic.WLST

Otherwise, at a command prompt, enter the following command:

java weblogic.WLST

A welcome message and the WLST prompt appears:

wls:/(offline)>

  1. To use WLST offline, enter commands, set variables, or run a script at the WLST prompt.
  2. For more information, see Creating and Configuring WebLogic Domains Using WLST Offline.

    To use WLST online, start a WebLogic Server instance (see Starting and Stopping Servers) and connect WLST to the server using the connect command.

    wls:/(offline)> connect('username','password','t3s://localhost:7002')
    Connecting to weblogic server instance running at t3s://localhost:7002 as username weblogic ...
    Successfully connected to Admin Server 'myserver' that belongs to domain 'mydomain'.

    wls:/mydomain/serverConfig>

    Note: BEA Systems strongly recommends that you connect WLST to the server through an SSL port or the administration port. If you do not, the following warning message is displayed:

Warning: An insecure protocol was used to connect to the server.
To ensure on-the-wire security, the SSL port or Admin port should be used instead.

For detailed information about the connect command, see connect.

Requirements for Entering WLST Commands

Follow these rules when entering WLST commands. Also see WLST Command and Variable Reference and WLST Online and Offline Command Summary.

Running Scripts

WLST incorporates two Jython functions that support running scripts: java weblogic.WLST filePath.py, which invokes WLST and executes a script file in a single command, and execfile(filePath.py) which executes a script file after you invoke WLST.

To run the script examples in this guide, copy and save the commands in a text file with a .py file extension, for example, filename.py. Use the text file with the commands for running scripts that are listed below. There are sample scripts that you can use as a template when creating a script.py file from scratch. For more information, see WLST Sample Scripts.

If the script will connect WLST to a running server instance, start WebLogic Server before running the script.

Invoke WLST and Run a Script

The following command invokes WLST, executes the specified script, and exits the WLST scripting shell. To prevent exiting WLST, use the -i flag.

java weblogic.WLST filePath.py
java weblogic.WLST -i
filePath.py

For example:

c:\>java weblogic.WLST c:/temp/example.py
Initializing WebLogic Scripting Tool (WLST) ...
starting the script ...
...

Run a Script From WLST

Use the following command to execute the specified script after invoking WLST.

execfile(filePath)

For example:

c:\>java weblogic.WLST
Initializing WebLogic Scripting Tool (WLST) ...
...
...
wls:/(offline)>
execfile('c:/temp/example.py')
starting the script ...
...

Importing WLST as a Jython Module

Advanced users can import WLST from WebLogic Server as a Jython module. After importing WLST, you can use it with your other Jython modules and invoke Jython commands directly using Jython syntax.

The main steps include converting WLST definitions and method declarations to a .py file, importing the WLST file into your Jython modules, and referencing WLST from the imported file.

To import WLST as a Jython module:

  1. Invoke WLST.
  2. c:\>java weblogic.WLST
    wls:/(offline)>

  3. Use the writeIniFile command to convert WLST definitions and method declarations to a .py file.
  4. wls:/(offline)> writeIniFile("wl.py")
    The Ini file is successfully written to wl.py
    wls:/(offline)>

  5. Open a new command shell and invoke Jython directly by entering the following command:
  6. c:\>java org.python.util.jython

    The Jython package manager processes the JAR files in your classpath. The Jython prompt appears:

    >>>

  7. Import the WLST module into your Jython module using the Jython import command.
  8. >>>import wl

  9. Now you can use WLST methods in the module. For example, to connect WLST to a server instance:
  10. wl.connect('username','password')
    ....

    Note: When using WLST as a Jython module, in all WLST commands that have a block argument, block is always set to true, specifying that WLST will block user interaction until the command completes. See WLST Command and Variable Reference.

Exiting WLST

To exit WLST:

wls:/mydomain/serverConfig> exit()
Exiting WebLogic Scripting Tool ...
c:\>

 


Getting Help

To display information about WLST commands and variables, enter the help command.

If you specify the help command without arguments, WLST summarizes the command categories. To display information about a particular command, variable, or command category, specify its name as an argument to the help command. To list a summary of all online or offline commands from the command line using the following commands, respectively:

help('online')
help('offline')

The help command will support a query; for example, help('get*') displays the syntax and usage information for all commands that begin with get.

For example, to display information about the disconnect command, enter the following command:

wls:/mydomain/serverConfig> help('disconnect')

The command returns the following:

Description:
Disconnect from a weblogic server instance.

Syntax:
disconnect()

Example:
wls:/mydomain/serverConfig>
disconnect()

 


Recording User Interactions

To start and stop the recording of all WLST command input, enter:

startRecording(recordFilePath,[recordAll])
stopRecording()

You must specify the file pathname for storing WLST commands when you enter the startRecording command. You can also optionally specify whether or not you want to capture all user interactions, or just the WLST commands; the recordAll argument defaults to false.

For example, to record WLST commands in the record.py file, enter the following command:

wls:/mydomain/serverConfig> startRecording('c:/myScripts/record.py')

For more information, see startRecording and stopRecording.

 


Redirecting WLST Output to a File

To start and stop redirecting WLST output to a file, enter:

redirect(outputFile,[toStdOut])
stopRedirect()

You must specify the pathname of the file to which you want to redirect WLST output. You can also optionally specify whether you want WLST output to be sent to stdout; the toStdOut argument defaults to true.

For example, to redirect WLST output to the logs/wlst.log file in the current directory and disable output from being sent to stdout, enter the following command:

wls:/mydomain/serverConfig> redirect('./logs/wlst.log', 'false')

For more information, see redirect and stopRedirect.

 


Converting an Existing Configuration into a WLST Script

To convert an existing server configuration (config directory) to an executable WLST script, enter:

configToScript([domainDir], [scriptPath], [overwrite], [propertiesFile], [deploymentScript])

You can optionally specify:

Note: configToScript() creates ancillary user-config and user-key files to hold encrypted attributes.

You can use the resulting script to re-create the resources on other servers. Before running the generated script, you should update the properties file to specify values that are appropriate for your environments. When you run the generated script:

For example, the following command creates a WLST script from the domain located at c:/bea/user_projects/domains/mydomain, and saves it to c:/bea/myscripts.

wls:/(offline)> configToScript('c:/bea/user_projects/domains/mydomain',
'c:/bea/myscripts')

For more information, see configToScript.

 


Customizing WLST

You can customize WLST using the WLST home directory, which is located at WL_HOME/common/wlst, by default, where WL_HOME refers to the top-level installation directory for WebLogic Server. All Python scripts that are defined within the WLST home directory are imported at WLST startup.

Note: You can customize the default WLST home directory by passing the following argument on the command line:
-Dweblogic.wlstHome=< >

The following table describes ways to customize WLST.

Table 2-1 Customizing WLST 

To define custom...

Do the following...

For a sample script, see...

WLST commands

Create a Python script defining the new commands and copy that file to WL_HOME/common/wlst.

WL_HOME/common/wlst/sample.py

Within this script, the wlstHomeSample() command is defined, which prints a String, as follows:

wls:/(offline)> wlstHomeSample()
Sample wlst home command

WLST commands within a library

Create a Python script defining the new commands and copy that file to WL_HOME/common/wlst/lib.

The scripts located within this directory are imported as Jython libraries.

WL_HOME/common/wlst/lib/wlstLibSample.py

Within this script, the wlstHomeSample() command is defined, which prints a String, as follows:

wls:/(offline)> wlstLibSample.wlstExampleCommand()
Example command

WLST commands as a Jython module

Create a Python script defining the new commands and copy that file to WL_HOME/common/wlst/modules.

This script can be imported into other Jython modules, as described in Importing WLST as a Jython Module.

WL_HOME/common/wlst/modules/wlstModule.py

A JAR file, jython.jar, containing all of the Jython modules that are available in Jython 2.1 is also available within this directory.


 

 

Skip navigation bar  Back to Top Previous Next