Importing Python Libraries included in Jython.jar in MAXIMO Automation Script

Importing Python Libraries included in Jython.jar in MAXIMO Automation Script

Some time back, I stumbled upon an article about the Python shutil module which can be used to zip files. I thought of trying this out using Maximo Automation Scripts. I started with a basic script to import the module as follows: 

Article content
Fig. 1

However, this did not seem to work. I got the following error while running the script.

Article content
Fig. 2

[ERROR] [MXServer] [CID-CRON-249] BMXAA7837E - An error occured that prevented the script for the null launch point from running.

ImportError: No module named shutil in <script> at line number 6

 I then appended the sys.path as follows:

Article content
Fig. 3

It still did not work and now I got the following error:

Article content
Fig. 4a
Article content
Fig. 4b

[ERROR] [MXServer] [CID-CRON-636] BMXAA7837E - An error occured that prevented the script for the null launch point from running.

ImportError: No module named path in <script> at line number 13

Caused by: Traceback (most recent call last):

File "<script>", line 13, in <module>

File "__pyclasspath__/Lib/shutil$py.class", line 10, in <module>

ImportError: No module named path

Now it seemed to indicate that it could not find the module “path” inside shutil

Importing other modules like “re” also did not seem to work. I then tried to append the  “jython.jar” which comes shipped with Maximo, but appending that too did not help. Moreover the path had to be hard-coded, which I wanted to avoid.

Finally, I tried the following (which actually uses the jython.jar) and eventually it worked for me. I have used the “re” module here. (I was able to import the “shutil” module too and use it to zip files).

Article content
Fig. 5
Article content
Fig. 6

[INFO] [MXServer] [CID-CRON-680] >>>>>>>>>>>>>>>>>>Extending path to /Lib

[INFO] [MXServer] [CID-CRON-680] PKKTESTPYTH> Calling....RE function....['foot', 'fell', 'fastest']

I was able to import other modules too from the jython.jar. For some modules, I had to import additional modules. For example if I have to use json, I had to import encodings for it to work.

Article content
Fig. 7

Hope this helps!!!


 


To view or add a comment, sign in

More articles by Priyaranjandas Kolambkar

Others also viewed

Explore content categories