|
From: David C. <dav...@gm...> - 2016-08-23 22:21:53
|
I just created my first servlet in Jython2.7.0 running on Apache2/Tomcat6.
When I tried to access my servlet with my browser, I got the following
error message:
HTTP Status 500 - Servlet.init() for servlet PyServlet threw exception
------------------------------
*type* Exception report
*message* *Servlet.init() for servlet PyServlet threw exception*
*description* *The server encountered an internal error that prevented it
from fulfilling this request.*
*exception*
javax.servlet.ServletException: Servlet.init() for servlet PyServlet
threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:745)
*root cause*
ImportError: Cannot import site module and its dependencies: No module
named site
Determine if the following attributes are correct:
* sys.path: ['/var/lib/tomcat6/webapps/jythonsample/WEB-INF/lib/Lib',
'__classpath__', '__pyclasspath__/']
This attribute might be including the wrong directories, such as
from CPython
* sys.prefix: /var/lib/tomcat6/webapps/jythonsample/WEB-INF/lib
This attribute is set by the system property python.home, although it can
be often automatically determined by the location of the Jython jar file
You can use the -S option or python.import.site=false to not import
the site module
org.python.core.Py.ImportError(Py.java:328)
org.python.core.Py.importSiteIfSelected(Py.java:1563)
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:116)
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:94)
org.python.util.PyServlet.createInterpreter(PyServlet.java:124)
org.python.util.PyServlet.reset(PyServlet.java:170)
org.python.util.PyServlet.init(PyServlet.java:90)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:745)
*note* *The full stack trace of the root cause is available in the Apache
Tomcat/6.0.39 logs.*
------------------------------
Apache Tomcat/6.0.39This is a web application, so I am not using the
command-line interface (so I cannot pass -S), nor am I starting the
interpreter from some Java code (so I cannot set property
python.import.site).
As a quick experiment, I copied the my $JYTHON_HOME/Lib directory into
jythonsample/WEB-INF/libs and this made the ImportError go away.
Symlinking the $JYTHON_HOME/Lib directory also made the ImportError go
away. But, both of these solutions seem dubious to me. If I copy the Lib
folder I feel like I have greater certainty that jython.jar and the Lib
directory are a matched set, but my Lib directory is 99M in size! If I
symlink the Lib folder, I save the 99M but I lose the certainty that I have
a matching jython.jar and Lib directory.
I have also considered creating a custom jython.jar that contains Lib, or
learning how to have a single, common jython.jar (and Lib) for all of my
servlets, but before I head down those paths I thought I would ask to see
what other people are doing.
David
|