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.
--------------------------------------------------------------
Sharon Lucas
IBM Austin, [EMAIL PROTECTED]
(512) 838-8347 or Tieline 678-8347
[EMAIL PROTECTED]
11/10/2008 09:18 AM
To
staf-users@lists.sourceforge.net
cc
Subject
[staf-users] Unable to call Java and Jython from Stax xml Job
Hi Folks,
I'm looking for an appropriate way to call a Jython Module from a STAX XML
job.
The situation is something like this:
I have a Java Class package comprising of 2 Java classes. Then I'm
accessing these classes from a Jython class.
Now I want to access this Jython module in a Stax Xml Job. I tried
importing the Jython module but it gives me Python Import error:
ImportError: no module named testCallJava1
I know there is something I'm missing like an environment variable or so.
Please suggest how is the best way to call this module (and java classes).
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
-------------------------------------------------------------------------
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