From: Robert W. B. <rb...@di...> - 2001-02-14 00:37:44
|
On Tue, 13 Feb 2001, George K. Thiruvathukal wrote: > 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? path tools are: 1. python.path in registry 2. python.prepath in registry 3. python.home usually set on command line "java -Dpython.home=/path" 4. sys.path.append("/path") in program or autoloaded site.py 5. Freezing the required modules. sys.path.append is equiv to what the registry python.path key does, and the autoloaded site.py file does as well. It usually works unless the sys.prefix is somehow off. Start with "java -Dpython.home=/usr/local/jython-2.0 myApp", and maybe print sys.prefix and sys.path to see what's up there. The python.prepath key in the registry pre-pends the path to sys.path if that's what you need. You can use the --deep --package commands with jythonc to freeze required modules. You could even try a shallow freeze of the modules with jythonc -j jythonLib.jar *.py, and put that jar in Classpath- but that's kinda extreme (and I haven't tried it to know for sure if it works :) Despite referring to jython's libs in this example, this applies equally to packages and .py files of yours. Best of luck. -Robert > 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 > |