Oracle WebLogic server ships with a set of tools for server administration and management. In the second chapter, we have learnt how to use the browser-based Administration console, which remains the first choice for WLS administrator. In this chapter we will learn about the WebLogic Scripting Tool (WLST) which is a command-line scripting environment that you can use to create, manage and monitor Oracle WebLogic Server domains.
Oracle WebLogicScripting Tool (WLST) is an advanced management tool, based on the Java scripting interpreter, Jython. In addition to supporting standard Jython features, such as local variables, conditional variables and flow control statements, WLST provides a set of scripting functions (commands) that are specific to WebLogic Server. You can even extend the WLST to suit your needs by following the Jython language syntax.
Jython is an implementation of the Python language in Java. It compiles Python code into Java bytecode and uses the JVM for this purpose. WLST uses Jython to access various objects within the WebLogic Server domain. These objects are called MBeans (Managed beans), that is, Java objects that represent resources to be managed.
WLST can be used in several modes; we can however group them in the following main three categories:
- Offline: Mostly used to create new domains like the configuration domain wizard
- Online: Used to perform online administration tasks just like the Administration console
- Embedded: Invoked directly from Java code
The WebLogic scripting tool can be located into the $MW_HOME/wlserver/common/bin folder of your distribution. It can be launched using the wlst command as shown here:
Oracle recommends using the offline mode to create domain templates, new domains based on existing templates, or extend an existing, inactive domain. It is discouraged to use this mode on a running domain of server since changes can be overwritten by other administration tools like the Web console or the WLST on line shell.
Running WLST in offline mode can be achieved with few little steps: at first set your environment by running the setWLSEnv script (the following example assumes you are running a Windows Machine):
Then you can launch your scripts in offline mode by passing them as argument to WLST:
Alternatively, you can just connect to the WLST by launching the wlst command (as shown in the former picture), and use the execfile command passing as parameter the script to execute:
Here is a sample WLST script which can be used to create a new WLS domain:
In this script, we are opening an existing domain template for domain creation, using the readTemplate command. Please note that, once you open a domain template, WLST is placed into the configuration bean hierarchy for that domain template, and the prompt is updated to reflect the current location in the configuration hierarchy.
You can traverse the hierarchical structure of configuration beans using commands such as cd, ls, and pwd in a similar way that you would navigate a file system in a UNIX or Windows command shell.
In this example, we are navigating first to the “Servers/AdminServer” location where we perform some administrative tasks (creation of Administration server); then we are heading for “Security/base_domain/User/WebLogic” bean hierarchy where we set some basic security settings.
If you specify a backslash character (\) in a string (e.g. Windows systems), for example when specifying a file pathname, you should precede the quoted string by “r” to instruct WLST to interpret the string in its raw form and ensure that the backslash is taken literally. This format represents standard Jython syntax.
- Next >>