On Mon, Nov 10, 2008 at 4:30 PM, Sharon Lucas <[EMAIL PROTECTED]> wrote:

>
> You need to make the Jython module accessible to the STAX job and make the
> Java classes it uses accessible to the STAX job before importing them.   To
> make Jython/Python modules accessible to a STAX job, you need to add the
> directory that contains the Jython module (e.g. the .py file) to sys.path
> before importing the Jython module.   For example, if the Jython module (the
> .py file) is in directory /tests/stax, you could do something like:
>    <script>
>    myPythonDir = '/tests/stax'
>
>    import sys
>    pythonpath = sys.path
>
>    # Append myPythonDir to sys.path if not already present
>    if myPythonDir not in pythonpath:
>      sys.path.append(myPythonDir)
>
>    # Import
>    import testcallJava1
>  </script>
>
> Also, please see section "4.1.1. Why aren't changes to imported Python
> modules picked up in my STAX job?" in the STAF/STAX FAQ at
> http://staf.sourceforge.net/current/STAFFAQ.htm#d0e2027 for more
> information on importing Python/Jython modules and for an example.
>
> To make Java classes accessible to the STAX job, they need to be in the
> CLASSPATH (if they aren't already).  Standard Java classes are automatically
> accessible so to access java.util.List and java.util.ArrayList for example,
> you could do:
>
>   <script>
>     import java.util.List
>     import java.util.ArrayList
>
>     javaList = java.util.ArrayList()
>     javaList.add('element1')
>     javaList.add('element2')
>   </script>
>
> Also, since the JSTAF.jar file is already in the CLASSPATH, you can use the
> java classes in it (like STAFUtil.wrapdata()) by simply do the following
> import within a <script> element in your STAX job:
>
>   <script>
>     import com.ibm.staf.*
>
>     data = 'This is machine {STAF/Config/Machine}'
>     request = 'RESOLVE STRING %s' % (STAFUtil.wrapData(data))
>   </script>
>
> Or, if you want to use other Java classes, you can add the directory
> containing the Java classes (or a jar file that contains the Java clases) to
> the CLASSPATH environment variable when registering the STAX service in the
> STAF.cfg file as follows using the J2 option to set the classpath using -cp
> (changing /tests/stax to whatever directory contains your Java classes):
>
> service STAX library JSTAF execute
> {STAF/Config/STAFRoot}/services/stax/STAX.jar \
>              OPTION JVMName=STAX OPTION "J2=-cp
> /tests/stax{STAF/Config/Sep/Path}{STAF/Env/CLASSPATH}"
>
> Of course, you'll need to shutdown and restart STAFProc then to pick up any
> changes in the STAF.cfg file.


Dear Sharon,

Thanks for the details.
I tried doing the same by adding to CLASSPATH the location of my Java
classes and adding the python module to sys.path same way as you mentioned.
Unfortunately I'm getting the same error ImportError: No module named
testCallJava1


I've kept my stax job file in C:\STAF\xml and the Jython modules along with
the Java Classed at C:\testing.

Please suggest if I'm still missing some thing.

Thanks and regards,
Rajat
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to