From: Updike, C. <Cla...@jh...> - 2006-05-17 15:00:40
|
I pass in the python home value as an absolute path via context init parameter in web.xml. =20 If needed, you can get the absolute path for the webapp home=20 as follows: try { sContextHome =3D URLDecoder.decode(sContext.getRealPath("/"), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new ServletException("Unable to URL decode context home."); }=20 where sContext is the ServletContext (of course, this won't work for=20 jar/war/ear). -Clark > -----Original Message----- > From: jyt...@li...=20 > [mailto:jyt...@li...] On Behalf=20 > Of Simon Brunning > Sent: Wednesday, May 17, 2006 10:11 AM > To: jyt...@li... > Subject: Re: [Jython-users] sys.path under Tomcat >=20 > On 5/17/06, Updike, Clark <Cla...@jh...> wrote: >=20 > Thanks for the help, Clark. >=20 > > I run scripts in Tomcat but not using PyServlet--instead using a=20 > > JythonProcessor class. This class has a static block that=20 > sets up the=20 > > stuff for the PythonInterpreter instances that run each script=20 > > invocation. >=20 > I do something similar. >=20 > > The relevant sections of the static > > block looks like this: > > > > static { > > > > ... > > > > Properties overriddenProps =3D System.getProperties(); > > Properties overridingProps =3D new Properties(); > > > > overridingProps.put("python.home", <python home>); > (snip) >=20 > This looks like the kind of thing I need - but how do I set=20 > this so that it will work regardless of where python home=20 > is? It'll always be a directory under WEB-INF, always in the=20 > same place relative to it, but I don't want to hard code an=20 > absolute path. I'd like it to just work regardless of where=20 > Tomcat is installed - or indeed what platform it's running on. >=20 > Come to think of it, ideally there should be some way of=20 > making this work in a strict J2EE server such as Websphere,=20 > which doesn't allow access to a file system at all. Is=20 > anything like that available? > Perhaps I'll need to look at Commons VFS for this. Still,=20 > it's not a show stopper - we are only deploying iunder Tomcat=20 > for the moment. >=20 > > I don't guarantee that this is the best way (or even the=20 > "right" way),=20 > > but it has worked for several years now in both Tomcat 4 and 5 in a=20 > > production environment. >=20 > That'll be good enough for me! |