Using external Libraries in Jython
Attention: Since Maximo / ICD 7.6.1 this method seems not to work anymore!
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:C:\Program Files\IBM\WebSphere\AppServer\profiles\ctgAppSrv01\installedApps\ctgCell01\MAXIMO.ear\lib\jython.jar
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");