# Using WebLogic Scripting Tool (WLST)

This section describes how to use WLST.

## Configuring Projects for WLST

Using OEPE, you can add WLST facet to your Java projects that run on Oracle WebLogic Server. Note that Utility projects are most suitable for this functionality.

To configure your project for WLST:

1. Either add the WLST facet when you create a faceted project, or add the facet to an existing project by right-clicking your project in the Project Explorer and selecting Properties from the drop-down menu. This opens the Properties dialog.

2. In the Properties dialog, select Project Facets on the left panel, and then select WLST from the Project Facet list.

3. Optionally, click Further configuration available to open the Configure WebLogic Scripting Tools dialog. This dialog allows you to configure WLST script source path and targeted runtime. When you have finished, click OK.

4. To complete adding WLST support to your project click Apply > OK on the Properties dialog.

## Creating New WLST Files

You can create a new WLST script as follows:

1. In the Project Explorer, right-click your WLST-enabled project and select New > Other from the drop-down menu.

2. On the New dialog, select WebLogic > WLST Script and then click Next to open the WLST Script dialog.

3. Specify the location for the new WLST file.

4. To specify the template to use, click Browse to open the TemplateName dialog, where you can choose one of the standard templates such as a default one, or specify a custom template of a module scope that you defined yourself. For more information, see Adding WLST Templates.Click OK.

5. In the WLST dialog click Finish.

A new WLST script file is created in the specified location. You can execute this file, as well as edit it using either the source editor, or a WLST file editor provided by OEPE. For more information, see Executing WLST and Editing WLST Script.

## Editing WLST Script

OEPE provides an editor for WLST files. The editor features the following:

- Syntax highlighting.

- Code completion for Jython and WLST built-in functions.

- WLST Help view that includes detailed WLST command reference materials.

To edit a WLST script:

- In the Project Explorer, double-click the WLST file. It opens in the editor.

## Adding WLST Templates

OEPE provides templates that you can use to create WLST files.

To add a new WLST template:

1. Select Window > Preferences from the top-level menu to open the Preferences dialog.

2. On the Preferences dialog expand the Pydev > Editor node, and then select Templates to open the list of available templates.

3. Click New on the Preferences > Templates screen to open the New Template dialog.

4. Enter the following information about your new template:

   - The template's name.

   - The template's scope: editor or module. If you select the module scope, your new template will appear in the selection list of templates when you create a new WLST script.

   - A brief description.

   - A pattern on which to base the template. You can define a custom pattern, or select one from the list of predefined patterns by clicking Insert Variable.

5. Click OK to close the completed New Template dialog.

   Notice that your new template is now listed in the Preferences > Templates dialog.

6. Click Apply > OK on the Preferences > Templates dialog.

## Navigating MBean Structures

When writing WLST script, you often need to navigate WebLogic runtime MBean structures. OEPE enables you to view the MBean hierarchy in the Servers pane.

To add or generate WLST code from MBean Hierarchy:

1. Open your WSLT file.

2. Click the Servers tab to open the Servers pane.

3. Start WLS by choosing Start from the context menu.

4. In the Servers view, expand the MBean Hierarchy node.

5. Right-click any child node and select Generate WSLT Code from the context menu.

   Note: This menu item is enabled only when the WSLT file is in focus.

## Using WLST Console

You can launch WLST in interactive mode in the Console view. This allows you to manage the Oracle WebLogic Server life cycle, monitor the server status, and prototype WLST script using WLST commands in the command line.

You use WLST console, activate the Console tab, and then select WLST > Oracle WebLogic Server Version from the tab menu.

To interact with the server, type WLST commands, for example `help()`.

To stop WLST, click Terminate on the Console menu.

## Executing WLST

To execute the WLST script, right-click the file in the Project Explorer, and select Run As > WLST Run.

WLST will be launched and the output displayed on the Console view.

## Debugging WLST Script

To debug the WLST script, right-click the file in the Project Explorer, and then select Debug As > WLST Run.

WLST debugger will start and the output will be displayed on the Console view.

The Pydev debugger allows you to do the following:

- Set break point in the WLST source file.

- Step over.

- Examine variables using the Variables view.

Note: The WLST script is executed with Jython interpreter in debug mode, as opposed to the `weblogic.WLST` interpreter.

## Importing Existing WLST Script into OEPE

If you import wlstModule into default name space using the from wlstModule import * statement, the global object cmo will not be available in this mode. You can work around this condition by either importing wlstModule with its own namespace:

    import wlstModule as wl

or by creating a local cmo object from the return of cd() statement:

    cmo=cd( MBEAN_PATH )

When importing existing WLST scripts into OEPE, be aware of the fact that Eclipse may flag WLST commands with "undefined variable" error.

To work around this problem, add following conditional import statement in the beginning of the file:

    if __name__ == '__main__':
           from wlstModule import *

This statement is intended to help the builder to locate the WLST command. The `wlstModule` will be imported only when the script is executed with Jython interpreter.

## Known Issues and Limitations

If you use WebLogic Server 9.2 on Windows Vista or Windows 7 operating system, you should avoid using Jython variable `os.environ` in your WLST script. Instead, you have to manually change the value of `BEA_HOME` and `WL_HOME` variables in the generated WLST script.