Adding Jython modules to the classpath
A Jython script, with an import command, works only if you have the respective module in the same directory.
In this command, wsadmin.sh -f /scirpts/jython/jvm.py, the jmv.py file contains the following line:
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
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.
More support for:
WebSphere Application Server
Administrative Scripting Tools (for example: wsadmin or ANT)
Software version: 6.1, 7.0, 8.0, 8.5, 8.5.5
Operating system(s): AIX, HP-UX, Linux, Solaris, Windows
Software edition: Base, Network Deployment
Reference #: 1268538
Modified date: 23 August 2007