|
From: <bc...@wo...> - 2001-02-13 09:57:46
|
[finn] > I have not yet look at this in depth, but I think the classes from lib & > classes are available as classes, but not as jython package namespaces. > You can test this by trying to load a class from withon the .py file > with java.lang.Class.forName(). I guess this should work, but the normal > jython import does not work. [Brian Zhou] >Unfortunately this (try load a <context>/WEB-INF/classes class from jython >servlet with java.lang.Class.forName()) does not work. > >What I'm trying to do actually is putting XMLC (see http://xmlc.enhydra.org) >compiled pages inside <context>. > >From within a jython servlet, "java.class.path" System property value does >not include <context>/WEB-INF/classes at all. So basically jython servlet >has no idea where to get these classes. > >Two observations, if I have testpkg.TestClass under ><context>/WEB-INF/classes: > >1. I happen to place org.python.util.PyServlet under tomcat_home/classes, if >I add >try { > Class.forName("testpkg.TestClass").newInstance(); >} >catch (Exception ex) { > System.err.println(e.toString()); >} >to PyServlet.java, class loading fails. Right, but I'm not going to add any special support for this. The PyServlet class (and the rest of jython.jar) should be placed under the <context>/WEB-INF/lib. >2. If I add the above code to a servlet within the same <context>, it loads >okay. Right, and it will load ok from within a jython script too. >Which is reasonable, but also suggests that servlet class loading does >something special when within a <context>. PyServlet need to borrow the same >logic. PyServlet will get the logic for free from the classloader that loaded jython.jar (but only when jython.jar is loaded from <context>/WEB-INF/lib). What we need to add is only the inspection of classes and jars found on ../lib and ../classes. The actual classloading magic is already handled by tomcat's servlet context logic. > I didn't test JSP, but I believe it should be the same as servlet. I have added this to PyServlet: props.setProperty("python.packages.directories", "java.ext.dirs,pyservlet.lib"); props.setProperty("pyservlet.lib", rootPath + File.separator + "WEB-INF" + File.separator + "lib"); props.setProperty("python.packages.paths", "java.class.path,sun.boot.class.path,"+ "pyservlet.classes"); props.setProperty("pyservlet.classes", rootPath + File.separator + "WEB-INF" + File.separator + "classes"); It seems to work, but I think we should have some kind of direct API for this purpose. PySystemState.add_classpath(String directoryPath) PySystemState.add_extdirs(String directoryPath) Any thoughs, Samuele? regards, finn |