WebLogic Scripting Tool (WLST)
Introduction:
The WLST is a
command-line scripting interface, which can be used to configure and manage
changes to WebLogic Server domains in a much simpler way by using scripts.
Though there are several ways to create, configure, and manage domains, the
scripting mode of WLST allows us to automate the tasks by using scripts.
Features:
- It is based on the Java scripting interpreter, Jython, which takes advantage of scripting language features, such as loops, flow control constructs, conditional statements, and variable evaluations.
- Best used in places where there are repeatable configurations primarily aimed at the preparation of an environment or where the configuration changes are applied, iteratively, across multiple nodes of a topology.
- The WLST script can also be run from an ant script.
- The Script contains WLST commands in a text file with a .py file extension, for example, services.py.
Automate repetitive tasks and complex procedures involved in configuring a
weblgic domain.
WLST Operating Modes:
- WLST can be used offline or online. Offline is used when a user is not connected to any WebLogic Server instance and is creating a new domain or updating an existing domain by interacting with the domain file and configuration templates. Online WLST is utilized when a user is connected to a running WebLogic Server instance and makes changes to the configuration artifacts or monitors the runtime data.
- WLST provides three modes of operation: interactive, script, and embedded modes. In the interactive mode, the users enter commands and view the response on a command-line prompt. Script mode lets the user supply a set of script commands in a file that the tool executes as a program. Embedded mode is where a user embeds the WLSTInterpreter in a Java application.
Classpath and Path Set Up:
The Classpath has
to be set by executing setWLSEnv or by executing setDomainEnv,
from the domain available.
e.g.,
%WLS_HOME%serverbinsetWLSEnv.cmd
This way of setting
the weblogic server environment involves adding an SDK to the PATH variable and
the WebLogic Server classes to the CLASSPATH variable and placing the wlst.jar
and jython.jar in the classpath.
Steps to run:
Once the classpath
is set, the WLST can be invoked in two ways:
- By executing “java weblogic.WLST”.
Once you are in the
wlst shell you will see this.
Initializing
WebLogic Scripting Tool (WLST) …
Welcome to Weblogic
Server Administration Scripting Shell
Type help() for
help on available commands
wls:/offline>
To execute any of
the attached scripts, do:
execfile(“security.py”)
- By executing “java weblogic.WLST services.py”
To connect to a
running instance of WLS,
wls:/(offline)>
connect(“weblogic”,”weblogic”,”t3://localhost:3001″)
To exit WLST, use
the exit() command.
Example:
Assumptions:
1. It
is assumed that there is one Admin server named “serverAdmin” and two Managed
servers named “MServer1” and “MServer2” and a cluster called “appCluster” which
has these two managed servers.
2. Note
that the script file name is “services.py”, and the user id and password for
connecting to weblogic are “weblogic/weblogic” and the “t3://localhost:3001”
points to the admin server. These are passed as command line arguments when
invoking WLST.
The
following example “services.py” will create the following in the domain:
Module
called sampleJmsSystemResource.
JMS
Template called MySampleJMSTemplate.
Connection
Factory with name and JNDI name sampleConnectionFactory.
JMS
Store named MServer1_SampleJMSStore and MServer2_SampleJMSStore.
JMS
Server named MServer1_SampleServer and MServer2_SampleServer.
JMS
Queue named MServer1/SampleQueue and MServer2/SampleQueue.
Distributed
Queue with name and JNDI name SampleDistributedQueue.
The steps to be followed:
Open a
command prompt.
Move to
the Bea directory which has the setWLSEnv or setDomainEnv and execute the same.
Move to
the directory where the script file (.py file) is placed.
Enter
the command: java weblogic.WLST services.py
weblogic weblogic t3://localhost:3001 (The port number should correspond to
your domain).
This
will run the script file and will connect to the server at the specified port
and create all the mentioned resources and will activate all the changes before
it disconnects from weblogic.
The
output can be seen in the command prompt. It will have all the print statements
that are mentioned in the py file.