Using external Libraries in Jython
One big limitation of the Jython environment of ICD and Maximo is that the base installation only provides the jython.jar file in version 2.5.2 without any libraries installed. Exactly these libraries can help enormous to write powerful scripts. Some useful examples are httplib and urllib for web access or smtplib for mail functions to just mention some of them. A full reference of included libraries in standard Jython can be found here.
What many users will now know is that the jython.jar file installed in Maximo/ICD does, compared to the original version of this file, include all standard libraries from the Lib directory. That’s quit cool, because we can easily use these libraries in our own scripts without copying any files to the servers. The only thing to know is the exact path of the jython.jar file on the server. This is basically in:
So on my Windows demo server for example it can be find under:
The clue to use these libraries is to add the new library path in your script. To do so you need the following code:
# Extend the sys Path import sys foundJython = False jythonLibPath = "C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\ctgAppSrv01\\installedApps\\ctgCell01\\MAXIMO.ear\\lib\\jython.jar\\Lib" for path in sys.path: if (path.find(jythonLibPath) != -1) : foundJython = True if (foundJython == False): sys.path.append(jythonLibPath) import re mystring = "Hello World!" test = re.match(r'(.*)World!', mystring) hello = test.group(1) print hello
Lines 1-9 are used to extend the sys-path. In the following lines I demonstrate the usage of the external library module re.
If you would like to use additional libraries, which are not included in the standard Jython package you need to copy the library source files to a new directory on the Maximo server and then include this directory in a similar manner like show above.
One improvement of the scenario show above is to use a property for the Jython path (for details see here). Change line 4 to the following code after you have created a Maximo property custom.jython.lib:from psdi.server import MXServer configData = MXServer.getMXServer().getConfig(); jythonLibPath = configData.getProperty("custom.jython.lib");
Thank you for these. I use your tips all the time,
have you ever had Java classes suddenly not be available in Jython inside of maximo?
Java classes from Maximo should be available in Jython inside Maximo. I haven’t seen a different behaviour so far. Do you use additional classes and are they stored in a different directory than businessobjects.jar?
Hi Matthias! Thank you very much for all the information on your website!
I have one question. How do I use mimetypes or mimetools modules in Jython.jar in C:\IBM\SMP\maximo\applications\maximo\lib?
Hi Matthias, Webshpere is installed in Linux machine, how the library path looks like ?
I tried this example today and got the following:
jythonLibPath = “C:\\IBM\\WebSphere\\AppServer\\profiles\\maximoAppSrv01\\installedApps\\maximoCell01\\MAXIMO.ear\\lib\\jython.jar\\Lib”
# Extend the sys Path
foundJython = False
for path in sys.path:
if (path.find(jythonLibPath) != -1) :
foundJython = True
if (foundJython == False):
mystring = “Hello World!”
test = re.match(r'(.*)World!’, mystring)
hello = test.group(1)
[‘__classpath__’, ‘__pyclasspath__/’, ‘C:\\IBM\\WebSphere\\AppServer\\profiles\\maximoAppSrv01\\installedApps\\maximoCell01\\MAXIMO.ear\\lib\\jython.jar\\Lib’]
Traceback (most recent call last):
File “”, line 16, in
AttributeError: type object ‘re’ has no attribute ‘match’