From: George K. T. <gk...@to...> - 2001-02-13 23:44:59
|
This proved to be very helpful. Apparently, the import of 'os' was where things got tripped up, because the path was not correct. I have now tried to repeat the same experiment by writing everything in Python and using the jythonc/jython combination and running into the same problem. What is the proper way to get classes to load in this scenario? I tried doing the usually sys.path.append() without much luck. George At 07:27 PM 2/13/2001 -0600, Robert W. Bill wrote: >Hi George, > >I tried it with lines commented out where something was missing (i.e.- >test2a), but it seemed to work fine. > >I have not seen the error, I am curious about your initialization in >the Java classs though. See test2run changes below... > >[George K. Thiruvathukal] > > I have a program that works when I run it standalone using jython: > > > > import os > > import os.path > > import sys > > > > from java.lang import System > > > > def go(out): > > title = "Example Apache JServ Servlet" > > out = System.out > > > > cwd = os.getcwd() > > addedDir = os.path.join(cwd, 'Python') > > out.println( 'current working directory = %s' % cwd) > > out.println( 'directory to add = %s' % addedDir) > > out.println( 'old path = %s' % sys.path) > > sys.path.append(addedDir) > > import Test2a > > out.println( 'new path = %s' % sys.path) > > out.println( 'now loading Test2a class and creating instance') > > out.println( 'object = %s' % Test2a.Test2a() ) > > out.close() > > > > if __name__ == '__main__': > > out = System.out > > go(out) > > > > When I run it through the PythonInterpreter using this wrapper: > > import org.python.util.PythonInterpreter; > > import org.python.core.*; > > > > public class Test2Run { > > public static void main(String []args) > > throws PyException > > { > > PythonInterpreter interp = > > new PythonInterpreter(); > > > > interp.exec("import Test2app"); > > } > > } > > >You could try setting python.home and python.path... > >import org.python.util.PythonInterpreter; >import org.python.core.*; >import java.util.*; > >public class Test2Run { > public static void main(String[] args) > throws PyException > { > PythonInterpreter interp; > Properties props = new Properties(); > props.setProperty("python.home","/usr/local/jython-2.0/"); > props.setProperty("python.path", "/home/modules:scripts"); > PythonInterpreter.initialize(System.getProperties(), props, > new String[0]); > interp = new PythonInterpreter(); > interp.exec("import Test2app"); > interp.exec('Test2app.go("whatever out should be") '); > } >} > >Just a guess. Good luck. > >-Robert |