3

Given the class

public class MyObject {
    public MyObject() {
        System.out.println("true = " + true);
    }
}

and the jython script

import sys
sys.path.append('my-custom.jar')
from my.custom import *
config = MyObject()

I get the following error when running in WAS ND 6 wsadmin.bat

Running c:\user\jem\projects\gmm/build/deploy/x.py
    WASX7209I: Connected to process "dmgr" on node dmgr_node using SOAP connector;  The type of process is: DeploymentManager
    WASX7017E: Exception received while running file "c:\user\jem\projects\gmm/build/deploy/x.py"; exception information:

com.ibm.bsf.BSFException: exception from Jython: Traceback (innermost last): File "", line 7, in ? java.lang.NullPointerException at java.lang.Class.isAssignableFrom(Native Method) at org.python.core.PyJavaClass.init_class_(PyJavaClass.java) ... about 20 lines clipped ... at org.eclipse.core.launcher.Main.run(Main.java:981) at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:339) at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:94)

    java.lang.NullPointerException: java.lang.NullPointerException

Do what now?

UPDATE:

It seems that the whilst inclusion of the jar into sys.path was enough to allow the class to be found, it was not sufficient to allow it to be instantiated. If I unzipped the jar into the existing path it worked.

So my new question is, why didn't adding the jar to sys.path work? Is it because the jython version is too old? I believe it is v2.1.

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
Synesso
  • 37,610
  • 35
  • 136
  • 207

2 Answers2

0

sys.path is for python class files not java ones. Also os.path is often used in conjunction to make sure you have a valid and full path. I don't know if it is impossible, but I have never had any luck using sys.path (in wsadmin) for python/jython files either, but I might just be doing it incorrectly.

Threadicide
  • 126
  • 7
0

Typically, I believe the sys.path is used for directories containing python modules (or .class files), which may be why it works when you unzip the jar. I think what you really want is to put your jar on the java classpath instead. This can be done by providing the path to your jar via the -wsadmin_classpath option when invoking wsadmin.

shelley
  • 7,206
  • 4
  • 36
  • 63
  • I cannot modify the classpath (or rather, I don't want to). This Q/A says what I am attempting should work. http://stackoverflow.com/questions/1730885/how-can-i-add-jars-dynamically-to-jython-inside-script – Synesso Feb 25 '12 at 10:12