From: <sp...@is...> - 2001-11-23 10:24:57
|
> At first you did use the wrong list. jython-dev is for development of=20= > jython > itself, your question belongs into jython-user. Secondly, you should=20= > mention > which jython and java versions you are using more prominently. It is = an > important information in order to assess your problem. Thanks for answering :) I was quite desperate as nobody has answered my=20= previous posts on jython-users, and it is not the first time it=20 happens.. So I did not found any alternative to direct posting to=20 jython-dev... I mentioned (in PS) that I was using jython-2.1a3, my=20 current JDK is MacOS X JDK 1.3.1- I have now switched to jython 2.0 > Did you look in jython-user archives? Perhaps somebody has had the = same=20 > problem. Yes, but I have not found anything... It's hard to make a query on that. > Are the classes java or jython classes? Are the files in the classpath=20= > or in > python.path resp.? If they are used from jython classes, did you=20 > compile your > program with jythonc with correct classpath set? The files are Java compiled files put in a jar. The sys-package-manager=20= finds the jar so this should be ok. As I said I can make a dir() on the=20= package name and it lists me the actual content of the package, but it=20= tells me this attribute error telling there is no Application attribute=20= in the package. The class is public, this is not a protection problem. After some experiment, putting my jar in /Library/Java/Extensions which=20= is the jre/lib/ext equivalent and starting jython interpreter I was able=20= to do : Jython 2.0 on java1.3.1 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import net.sourceforge.spedit.app >>> net.sourceforge.spedit.app.Application() >>> ...everything went fine (note: I switched back to jython 2 to see if the problem was still = there) Afterwards I tried another way, removing my package from the Extensions=20= and starting the jython interpreter with -cp SPEdit.jar, which is the=20= package containing my classes. So I made the following: Jython 2.0 on java1.3.1 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import net.sourceforge.spedit.app >>> net.sourceforge.spedit.app.Application() Traceback (innermost last): File "<console>", line 1, in ? AttributeError: java package 'net.sourceforge.spedit.app' has no=20 attribute 'Application' This puzzles me really, because as I said: >>> dir(net.sourceforge.spedit.app) ['Application', 'AuthorDisplay', 'DBView', 'NavigationTree', '__name__'] So jython actually knows the package.. Any clues? Cheers, -- S=E9bastien. |
From: <sp...@is...> - 2001-11-23 10:34:51
|
Le vendredi 23 novembre 2001, =E0 11:28 AM, Jan Wender a =E9crit : > On Fri, Nov 23, 2001 at 11:24:53AM +0100, S=E9bastien Pierre wrote: >> >> Jython 2.0 on java1.3.1 (JIT: null) >> Type "copyright", "credits" or "license" for more information. >>>>> import net.sourceforge.spedit.app >>>>> net.sourceforge.spedit.app.Application() >> Traceback (innermost last): >> File "<console>", line 1, in ? >> AttributeError: java package 'net.sourceforge.spedit.app' has no >> attribute 'Application' >> > Is it possible that the Application class depends on some other class?=20= > If so, > are the other classes also in the classpath? > No every dependency is packaged into the jar. I mean it works when I put=20= the jar in the Extensions directory...I cannot figure out why the=20 behaviour is different when I set the classpath manually. This obviously=20= isn't caused by the JDK as jython is able to list the package content. I=20= will try on another machine... Desperatly yours, -- S=E9bastien. |
From: <sp...@is...> - 2001-11-23 10:45:48
|
I have made tests on a linux machine jdk-1.3.1/jython-2.1a3, I went fine=20= with both SPEdit.jar in jre/lib/ext and in local dir with -cp option. So=20= I can only conclude this is a MacOS X issue, but to submit a bug I have=20= to understand why. I do not know how Jython does to get access classes=20= in packages, but the think is that it is actually able to list the=20 content of the package but cannot access it. What are the difference=20 between the mechanims behind dir() and those involved in attributes=20 resolution? Cheers, -- S=E9bastien. |
From: <bc...@wo...> - 2001-11-26 10:19:42
|
[Sebastien Pierre] >I have made tests on a linux machine jdk-1.3.1/jython-2.1a3, I went fine >with both SPEdit.jar in jre/lib/ext and in local dir with -cp option. So >I can only conclude this is a MacOS X issue, but to submit a bug I have >to understand why. I do not know how Jython does to get access classes >in packages, but the think is that it is actually able to list the >content of the package but cannot access it. What are the difference >between the mechanims behind dir() and those involved in attributes >resolution? The difference is between package-loading and class-loading. The java environment have no usefull way of detecting which classes exists in a java package so Jython fake it by scanning all the .jar files and directories it can find. Jython looks for the properties of: >>> import java >>> java.lang.System.getProperty("java.class.path") 'd:\\java\\jdk1.4\\jre\\lib\\rt.jar;.....' >>> java.lang.System.getProperty("sun.boot.class.path") 'D:\\JAVA\\JDK1.4\\jre\\lib\\rt.jar;D:\\JAVA\\JDK1.4\\....' >>> java.lang.System.getProperty("java.ext.dirs") 'D:\\JAVA\\JDK1.4\\jre\\lib\\ext' 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. regards, finn |
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. |
From: <bc...@wo...> - 2001-11-26 15:07:19
|
[Sebastien Pierre] >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 How does java find jython.jar with that command line? Is jython.jar located in the jre/lib/ext directory? It probably shouldn't be. >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) Since this doesn't work, there is no way jython can find the Application class (We are ignoring sys.path loading here). >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. Nope, can't blame jython for this. My guess is that jython.jar exists in jre/lib/ext and that is the reason that jython can only load other code that also reside on the boot-classpath. >I have written the equivalent in Java: [...] >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' Hmm, that output can't be from your little java program. >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. regards, finn |
From: <sp...@is...> - 2001-11-26 15:26:55
|
Le lundi 26 novembre 2001, =E0 04:10 PM, Finn Bock a =E9crit : > How does java find jython.jar with that command line? > > Is jython.jar located in the jre/lib/ext directory? It probably > shouldn't be. [..] | My guess is that jython.jar exists in jre/lib/ext and that is the=20 reason | that jython can only load other code that also reside on the | boot-classpath. Yes it actually is. I put everything I need in the jre/lib/ext dir to=20 avoid classpath problems. Is there a side effect of putting jython in=20 this directory? I cannot see why putting the jython.jar in this=20 directory would prevent to load classpath items physically located=20 elsewhere? >> I have written the equivalent in Java: > > [...] > >> When I run it: >> java -cp SPEdit.jar:. Test >> >> I get: >> *sys-package-mgr*: processing new jar,=3D20 >> = '/Users/spierre/Projects/SPEdit/prototype/build/SPEdit.app/Contents/Resour= =3D >> ces/Java/SPEdit.jar' > > Hmm, that output can't be from your little java program. Well I did not put anything else than the program. The jython.jar seems=20= to be automatically loaded and processes the classpath items. I think=20 even if the -cp option is specified the jvm goes looking into the=20 /jre/lib/ext. This is strange but understandable...maybe putting=20 everything in the ext directory is not that a good idea... I will try by=20= moving the jython.jar and see what happens... Thanks, -- S=E9bastien. |
From: <bc...@wo...> - 2001-11-26 16:31:01
|
>| My guess is that jython.jar exists in jre/lib/ext and that is the reason >| that jython can only load other code that also reside on the >| boot-classpath. > >Yes it actually is. I put everything I need in the jre/lib/ext dir to=20 >avoid classpath problems. Is there a side effect of putting jython in=20 >this directory? It seems like the classloader that is loading extentions does not itself search the classpath. I can't find a place in the Java documentation stating that it is the case, but you can verify that it is by putting your Test.class in a .jar file and copy the jar file to jre/lib/ext. I predict that the Test program also fails then. >I cannot see why putting the jython.jar in this=20 >directory would prevent to load classpath items physically located=20 >elsewhere? It is the classloader that loaded the jython.jar that decides. When running with jython.jar in my jre/liv/ext, I get see that it is an ExtClassLoader that loaded jython. Jython 2.1b1 on java1.4.0-beta3 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import org >>> org.python.core.Py.classLoader sun.misc.Launcher$ExtClassLoader@9fef6f >>> I get: >>> *sys-package-mgr*: processing new jar,=3D20 >>> = >'/Users/spierre/Projects/SPEdit/prototype/build/SPEdit.app/Contents/Resour= >=3D >>> ces/Java/SPEdit.jar' >> >> Hmm, that output can't be from your little java program. > >Well I did not put anything else than the program. The jython.jar seems >to be automatically loaded and processes the classpath items. Yuck. >I think >even if the -cp option is specified the jvm goes looking into the=20 >/jre/lib/ext. This is strange but understandable... That part is documented: http://java.sun.com/docs/books/tutorial/ext/basics/load.html regards, finn |