WLST - Getting Started (Hello World)

> Procedural Languages > Weblogic Scripting Tool (WLST)

1 - About

The execution of a Wlst Script can happen in the following three modes:

  • interactive: on the command line
  • scripting: in batch scripts that are supplied in a file (Script Mode, where scripts invoke a sequence of WLST commands without requiring your input)
  • embedded: in Java code.

3 - How to

3.1 - start the WLST console

3.1.1 - From a shell with Java

  • Environment Configuration
Environment variable Path
CLASSPATH WebLogic Server classes
PATH WL_HOME\server\bin

Script to set both variables:

  • Windows: WL_HOME\server\bin\setWLSEnv.cmd
  • Linux: WL_HOME\server\bin\setWLSEnv.sh
  • Invoking the console Console
java
   [ -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=DemoTrust ]
   weblogic.WLST
   [ -loadProperties propertyFilename ]
   [ -skipWLSModuleScanning ]
   [ [-i] filePath.py ]

where:

  • the first parameter is for a SSL connection
  • the second option is to load a property file
  • -skipWLSModuleScanning is to reduce startup time by skipping package scanning and caching for WLS modules
  • -i prevent WLST from exiting after the script is executed
  • filePath.py is a script

Example:

C:\Oracle\Middleware1035\wlserver_10.3\server\bin>java weblogic.WLST
Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

wls:/offline>
Advertising

3.1.2 - From a shell script

This wlst.cmd:

FMW_HOME\oracle_common\common\bin\wlst.cmd

calls this one:

FMW_HOME\wlserver_10.3\common\bin\wlst.cmd

3.1.3 - From Windows Start Menu: Weblogic Scripting Tool

3.1.4 - From Eclipse

3.2 - Start an "Hello World" script

The script:

HelloWorld.py
import sys
 
if len(sys.argv) > 1:
    print sys.argv[1]+" from the console" 
else:
    print "Hello World from the script"

3.2.1 - From the shell

java weblogic.WLST HelloWorld.py "Hello World"
Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Hello World from the console
Advertising

3.2.2 - From Eclipse

3.2.3 - From the WLST console

import sys
sys.argv = ['Hello World', 'arg2']
execfile('HelloWorld.py')

3.2.4 - From Ant

<property name="wls.lib.dir" location="C:/Oracle/Middleware1035/wlserver_10.3/server/lib" />
<path id="wls.classpath.id">
    <pathelement location="${wls.lib.dir}/weblogic.jar" />
</path>
<taskdef name="wlst" classname="weblogic.ant.taskdefs.management.WLSTTask" classpathref="wls.classpath.id" />
<target name="WlsHelloWorld">
    <wlst fileName="helloworld.py" classpathref="wls.classpath.id" arguments="'Hello World'"/>
</target>
ant WlsHelloWorld
Buildfile: D:\HelloWorld\build.xml

WlsHelloWorld:
     [wlst] 'Hello from the console

BUILD SUCCESSFUL
Total time: 3 seconds

4 - Support

4.1 - taskdef class weblogic.ant.taskdefs.management.WLSTTask cannot be found

taskdef class weblogic.ant.taskdefs.management.WLSTTask cannot be found
 using the classloader AntClassLoader[]

The classpath element must be added to the taskdef.

<taskdef name="wlst" classname="weblogic.ant.taskdefs.management.WLSTTask" classpathref="wls.classpath.id"/>

5 - Documentation / Reference

Advertising