From: Russo, T. <to...@st...> - 2001-07-19 19:18:40
|
Hi, I'm having some trouble using jython from within a jsp page. I'm running Tomcat 3.2.2, jython 2.0, java 1.3.1 and Win2K. The following code demonstrates the error: <%@ page import="org.python.core.*" %> <%@ page import="org.python.util.PythonInterpreter" %> <% PythonInterpreter interp = new PythonInterpreter(); // Tell jpython where to find importable modules. This is a bit of a hack. interp.exec("import sys"); interp.exec("sys.path.append('C:\\jython\\.')"); interp.exec("sys.path.append('C:\\jython')"); interp.exec("sys.path.append('C:\\jython\\Lib')"); PyList path = (PyList)interp.eval("sys.path"); //interp.exec("import socket"); //<--- this line causes the error %> <html> <head><title>test</title></head> <body> <%= path %> </body> </html> When executed as is, the output is: ['.', 'C:\\jython\\.', 'C:\\jython', 'C:\\jython\\Lib'] which is as expected. However, if I uncomment the line interp.exec("import socket"); I get: <snip> Error: 500 Internal Servlet Error </snip> <snip> Root cause: Traceback (innermost last): File "", line 1, in ? File "C:\jython\Lib\socket.py", line 13, in ? ImportError: No module named python </snip> The offending line in socket.py is: import org.python.core This module should be loaded from jython.jar, which is in the WEB-INF\lib folder of my web application. jython.jar is not on the classpath; rather it gets loaded by the jsp server when this page is requested. When I put jython.jar on the classpath, everything works fine. I'd rather not do that though, because it prevents me from zipping everything into an exportable .war file. I'm setting sys.path manually because it doesn't seem to be set. I guess the ultimate question is: is it possible to use jython.jar when it's not on the classpath? I've read that there were some problems with jpython.jar and class loaders. I changed to jython.jar but the problems don't seem to have gone away. Does anyone know a fix for this? thanks much _t |