Photo of the cover of WebSphere Application Server Administration Using Jython

Official companion web site

Installing a Library of Jython Scripts

Most recently modified on 2010-05-26
Available from
Back to home page Back to table of contents page
Sample Library of Python Scripts

Anybody who writes python scripts for WebSphere Applican Server quickly discovers the need for libraries of scripts. Finding documentation that will help you create and use libraries of your own python scripts is not easy. It is also not easy to find documentation that tells you how to import the WAS script objects into your script libraries. This article will walk you through that process.

In order to create, install and use a python library of your own creation, you must:

  • Make the WAS script objects available to your scripts
  • Load your scripts as profiles when wsadmin starts
  • Run any initialization code that your scripts might require

In order to get wsadmin to load your python script library, you will have to write something that IBM calls a profile script. This is a script that wsadmin runs before its environment is fully initialized. Let us write some python code that displays the environment of wsadmin at this not-so-fully-initialized time. Download and save it on your file system. Next, call wsadmin using as a profile. You will have to type the fully qualified name of the profile. On my system, that name is /home/localuser/ Then, we will redirect the output of wsadmin to a file on my system. The command line to do this will look something like this. Adjust the path names to match the realities of your WAS installation.

./ -profile /home/localuser/ -conntype none -c "print 'Hello World!' " > ~localuser/junkOutput.txt

Open junkOutput.txt and do a text search for the following words. You won't find them. You will find lots of other stuff, but not these words.

  • AdminConfig
  • AdminControl
  • AdminApp
  • AdminTask
  • Help

It is very hard to write administrative scripts that do not use one or more of these script objects. We are going to modify the initialization environment of wsadmin so that the five script objects become available. We will use a profile script called in order to make the WAS script objects availible to our library scripts and in order get wsadmin to load our library scripts.

Line 7 through line 11 make the five WAS script objects available to our various library scripts. This is how those lines work. Python has a sys module. By default, it is one of the modules that wsadmin imports automatically. One of the data structures of the Python sys module is a dictionary called "modules". We make the five WAS scripting objects available for our library scripts by inserting them into the sys.modules dictionary. Once we do that, we can load library modules that import any or all of the administrative script objects.

The sample script library files are in a zip file that you can download. Unpack the zip file in a location of your choice. You will find a file and two subdirectories: server and misc. In order to import each of our script library files, we must first add the fully qualified path to server and misc to wsadmin's classpath. Then we can import the individual files in those folders.

Lines 23 and 29 add our folders to wsadmin's classpath. Notice that those two lines depend on a jython variable called "scriptDirectory". That variable gets set on line 17 of You have to modify this line to reflect the location where you unpacked our sample library zip file.

The last thing you have to do is modify your file. If you look at line 86 of the sample file, you will find a property called In our sample file, that property has three file names. In the file in the config directory of your deployment manager profile, that same property probably has only two file names. Look at the last file name in the property in our sample file. Line 86 looks like this:; /opt/IBM/WebSphere/AppServer/bin/; /home/localuser/scriptLibrary/

In order to make it fit on this page, we split the line above at each semicolon. In real life, the above sample would all be on one line and theere would be no spaces anywhere. Notice that the last file name on that line is the fully qualified file name of our profile file. Make that path match the realities of your system and you have just loaded our sample script library into wsadmin.

To prove that you successfully loaded our sample library files, start wsadmin in interactive mode. Make sure that jython is your default language. When you get a wsadmin prompt, you can type:

dir( serverFunctions )

print serverFunctions.__doc__

print serverFunctions.createAdditionalClusterMembers.__doc__

The first line will show you all the public names in the serverFunctions module. The second will show you the documentation for the serverFunctions module as a whole. The third will show you the documentation for one method in the serverFunctions module.

Arthur Kevin McGrath


The author is an engineer with the consulting firm, Contract Engineers. He has consulted and lectured extensively since 1987 about the infrastructure that makes electronic commerce possible. His publications include Leading Practices for WebSphere Dynamic Process Edition V6.2 (SG24-7776-00) and Websphere Application Server Administration Using Jython (ISBN 0137009526), the definitive book on WAS scripting.

Photo of the author
Click here to schedule a speaker at your location Click here to inquire about consulting for your company Click here to inquire about training for your company