From: Robert W. B. <rb...@di...> - 2001-01-23 00:00:54
|
Hello, (tnx for the speedy reply Finn!) Unfortunately, I'm still stuck. Maybe this is different enough that I should include some code examples and the full story: In using Tomcat-3.2.1, Jython-2.0, sun jdk-1.2.2, win98. I've placed jython.jar in %TOMCAT_HOME%\webapps\jython\WEB-INF\lib and would also like to place the below servlet (and many frozen modules) in the same lib directory as jyDispatch.jar. Ahhh, the dream of an entirely frozen webapp that could be delivered to clients in a *.war file just like all the java servlet/JSP webapps out there, but secretly using Jython :) Here's the code: -------------------------------------------------------------- #filename: jyDispatch.py import sys sys.prefix="." from javax import servlet from javax.servlet import http import os class jyDispatch(http.HttpServlet): def service(self,req, res): 'Jython servlet dispatcher' mtimes = {} ctx = self.getServletContext() #test junk out = res.getWriter() out.println("<br>sys.path=" + str(sys.path)) out.println("<br>sys.prefix=" + str(sys.prefix)) out.println("<br>cwd=" + str(sys.getcwd())) # Get the path of the *.py file to be dispatched path = ctx.getRealPath( req.getServletPath() ) mtime = os.stat(path)[7] #Other stuff... ---------------------------------------------------------------- The "sys.prefix='.'" was added as suggested and it was compiled with the implied: jythonc -j jyDispatch.jar -a jyDispatch.py However, none of the javaos code is accessible. getcwd, and stat in the example above are hidden. It seems very much like the example you (Finn) used, but I'm having no luck muxing with the sys.prefix or sys.path in the servlet to get around this. All hints and comments are welcome as always :) Thanks in advance. -Robert [Robert W. Bill] >>Freezing servlet applications have resulted in difficulty with >>the javaos module. The simple scenario is I need to use >>os.stat(file), but all frozen applications return the error: >> >> AttributeError: class 'org.python.modules.os' has no >> attribute 'stat' >> >>When using jythonc, i've tried: >> >> jythonc -a -j app.jar jyDispatch.py >> jythonc -a -j app.jar jyDispatch.py javaos os re string >> jythonc -c -j app.jar jyDispatch.py javaos etc.... >> >>All result in the above AttributeError. >> >>I've assumed stat requires os + javaos- does it? >Yes. >>How do I freeze an application so that I can use it? >When I just tried to freeze this little module I got an NPE: > > import os > print os.stat > >This is an unintended sideeffect on a hack I added to satisfy >site.py's use of the os module. It occur when sys.prefix is None >which typically happens for frozen applications. > >Changing the module to: > > import sys > sys.prefix = "." > > import os > print os.stat > >and it runs as expected. I compiled the module with the >simple: > > jythonc.bat -j app.jar -a app.py >I'm not 100% sure this is the situation you are seeing, but >please give it a try. >regards, >finn |