|
From: Robert W. B. <rb...@di...> - 2001-02-13 20:30:04
|
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
|