IBM Support

Adding Jython modules to the classpath

Troubleshooting


Problem

A Jython script, with an import command, works only if you have the respective module in the same directory.

Symptom

In this command, wsadmin.sh -f /scirpts/jython/jvm.py, the jmv.py file contains the following line:

import common

The term "common" is nothing but a sample Jython script called common.py.

The only way to get this to work is to run the wsadmin command from the exact directory that common.py exists in. Otherwise, it fails with the following exception:

WASX7209I: Connected to process "dmgr" on node manager using SOAP connector;  The type of process is: DeploymentManager                
WASX7017E: Exception received while running file "/scripts/61/jython/jvm.py";
exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last): File "<string>", line 26, in ?
ImportError: no module named common

Cause

During the "import" operation, Jython is searching for the files only in the path, which are registered with its own registry (by default, working directory (./) will get registered). If you need to include your own custom files or modules, then the path of custom files should be registered with Jython. At the time of loading, this can be done through the System property python.path as key, and the custom file path as value.

Resolving The Problem

For example, if you have 2 Jython files for import,

  • test1.py is in the profile_root/profile_name directory
  • test2.py is in the profile_root/ directory

Then run the wsadmin command like this,

wsadmin.sh -lang jython  -javaoption
"-Dpython.path=<profile_root/profile_name>:<profile_root>"

When Jython is loaded, it will append the paths in the property python.path to its registry, and during execution, it searches for the files in the paths that are registered in its registry.

[{"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Administrative Scripting Tools (for example: wsadmin or ANT)","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"9.0;8.5.5;8.0;7.0","Edition":"Base;Network Deployment","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21268538