From: <sp...@is...> - 2001-11-26 12:18:25
|
> So when the "import net.sourceforge.spedit.app" works it means that > jython have found the SPEdit.jar file and scanned it. > > You can verify that the SPEdit classes can be found by the JVM with = this > code: > >>>> import java >>>> java.lang.Class.forName("net.sourceforge.spedit.app.Application") > > That should take jython out of the equation and if it doesn't work it > means you have not added SPEdit.jar to your OSX classpath correctly. You pointed interesting things with the Java reflection. Here is what I=20= do: > java -Dpython.home=3D"/sw/share/jython" -cp SPEdit.jar=20 org.python.util.jython -v *sys-package-mgr*: processing modified jar,=20 = '/Users/spierre/Projects/SPEdit/prototype/build/SPEdit.app/Contents/Resour= ces/ Java/SPEdit.jar' *sys-package-mgr*: rewriting cachefile for=20 = '/Users/spierre/Projects/SPEdit/prototype/build/SPEdit.app/Contents/Resour= ces/ Java/SPEdit.jar' *sys-package-mgr*: writing modified index file So here the jar that contains the classes I want is loaded. But when I do: >>> import java >>> java.lang.Class.forName("net.sourceforge.spedit.app.Application") I get: Traceback (innermost last): File "<console>", line 1, in ? java.lang.ClassNotFoundException: net.sourceforge.spedit.app.Application at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:297) at java.lang.ClassLoader.loadClass(ClassLoader.java:253) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:120) at java.lang.reflect.Method.invoke(Native Method) at=20 = org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:158)= at=20 = org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:166)= at org.python.core.PyObject.__call__(PyObject.java:272) at org.python.core.PyObject.invoke(PyObject.java:2105) at org.python.pycode._pyx2.f$0(<console>) at org.python.pycode._pyx2.call_function(<console>) at org.python.core.PyTableCode.call(PyTableCode.java:155) at org.python.core.Py.runCode(Py.java:1055) at org.python.core.Py.exec(Py.java:1076) at=20 org.python.util.PythonInterpreter.exec(PythonInterpreter.java:145) at=20 = org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java= : 87) at=20 = org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.ja= va: 68) at=20 = org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.ja= va: 42) at=20 org.python.util.InteractiveConsole.push(InteractiveConsole.java:83) at=20 org.python.util.InteractiveConsole.interact(InteractiveConsole.java:62) at org.python.util.jython.main(jython.java:178) java.lang.ClassNotFoundException: java.lang.ClassNotFoundException:=20 net.sourceforge.spedit.app.Application Then I do: >>> import net import: 'net' as java package >>> dir(net.sourceforge.spedit.app) and I get : ['Application', 'AuthorDisplay', 'DBView', 'NavigationTree', 'Pool',=20 '__name__'] This is quite strange as I have explicitely specified the SPEdit.jar as=20= a classpath item...The problem is solved when I put the SPEdit.jar into=20= the jre/lib/ext MacOS X equivalent. In this case Jython has managed to index the SPEdit.jar, which is shown=20= by the result of the dir function call, but Java itself is then unable=20= to locate the SPEdit.jar, as if the classpath has been reset by jython. I have written the equivalent in Java: class Test { public static void main (String[] args) { try { =20 = System.out.println(Class.forName("net.sourceforge.spedit.app.Application")= ); } catch ( Exception e ) { System.out.println("Class not=20 found.\n\t"+e.toString()); e.printStackTrace(); } } } When I run it: java -cp SPEdit.jar:. Test I get: *sys-package-mgr*: processing new jar,=20 = '/Users/spierre/Projects/SPEdit/prototype/build/SPEdit.app/Contents/Resour= ces/ Java/SPEdit.jar' class net.sourceforge.spedit.app.Application So actually Java find the class. This seems to point that the bug may be=20= in Jython overriding in some way the class path, so that URLClassLoader=20= is unable to find the classes anymore. Cheers, -- S=E9bastien. |