From: <bc...@wo...> - 2001-11-09 15:11:19
|
[John Goerzen] >bc...@wo... (Finn Bock) writes: > >> Try calling >> >> Py.getSystemState().setClassLoader(this.getClass().getClassLoader()); >> >> It will effectively disable attempts to import java classes from >> sys.path and instead only try to load them from the MultiClassLoader. > >Almost there!! > >(Thanks to you and Jeff Emanuel for all your help). > >I have thinks WORKING! but only if I use Jeff's trick of: >interp.set("ListBO", this.getClass()). If I try to >"import quovix" or "from quovix.business.util import ListBO" from >Python after setting the classloader per your instructions, Python >gives an "ImportError: no module named quovix". That is because java have no solid way of querying a classloader about which java packages it can serve. To load a java package from from sys.path, we have to do a directory listning to discover the available java directories. When disabling java loading from sys.path (by setting the classloader) we also disable this method of java package discovery. Take another look at the PyServlet example: > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jython/jython/org/python/util/PyServlet.java?annotate=1.11#73 and notice the calls to sys.add_package(..) and sys.add_classdir(..). These calls will give some hints to the package manager that one of the custom classloaders in the environment is able to serve additional java packages. It is important to know that the sys.add_XXX() methods does not enable loading of java classes from these sources. The methods only allow loading of java packages. >Oddly, it can import things like java.util.Date. Not odd at all. Jython scans the rt.jar file for all java classes and build a list of available java package from this list. >I'm unsure why it can't find my own >classes -- obviously the MultiClassLoader can because all this stuff >is being called from ListBO itself. So it's a bit strange. But I can >work around that certainly. > >Also I'm curious why this works: > >interp.exec("import ListBOFoo"); >Class pclass = (Class) interp.eval("ListBOFoo.ListBOFoo").__tojava__(Class.class); > >But this doesn't: > >interp.exec("mod = __import__('ListBOFoo')"); >Class pclass = (Class) interp.eval("mod.ListBOFoo").__tojava__(Class.class); > >The second dies on the eval claiming that there is no such symbol in >Python. Not a biggie but a weird thing anyway. Which symbol? Do you have a stacktrace? >Thanks for all your help! You's welcome. regards, finn |