From: Samuele P. <pe...@in...> - 2001-05-21 20:29:07
|
Hi. [Frode Reinsnes] > I have used Jython for a while, but I haven't use Jythonc before. So I think > I have miss something, but are not able to se what. > > I have this simple python file named test.py: > > import java.lang > print 'java.lang:',dir(java.lang) > > If I compile it with Jythonc I don't get expected result > > c:\Document\Test>jythonc --jar test.jar -c test.py > : > c:\Document\Test>java -jar test.jar test > java -jar test.jar test > java.lang: ['__name__'] > > > But if I use the interpreter I get the expected result. > > c:\Document\Test>jython test.py > jython test.py > java.lang: ['AbstractMethodError', 'ArithmeticException', > 'ArrayIndexOutOfBoundsException', 'ArrayStoreException', 'Boolean', 'Byte', > 'Character', 'Class', 'ClassCastException', 'ClassCircularityError', > 'ClassFormatError', 'ClassLoader', 'ClassNotFoundException', > 'CloneNotSupportedException', 'Cloneable', 'Comparable', 'Compiler', > 'Double', 'Error', 'Exception', 'ExceptionInInitializerError', 'Float', > 'IllegalAccessError', 'IllegalAccessException', 'IllegalArgumentException', > 'IllegalMonitorStateException', 'IllegalStateException', > 'IllegalThreadStateException', 'IncompatibleClassChangeError', > 'IndexOutOfBoundsException', 'InheritableThreadLocal', 'InstantiationError', > 'InstantiationException', 'Integer', 'InternalError', > 'InterruptedException', 'LinkageError', 'Long', 'Math', > 'NegativeArraySizeException', 'NoClassDefFoundError', 'NoSuchFieldError', > 'NoSuchFieldException', 'NoSuchMethodError', 'NoSuchMethodException', > 'NullPointerException', 'Number', 'NumberFormatException', 'Object', > 'OutOfMemoryError', 'Package', 'Process', 'Runnable', 'Runtime', > 'RuntimeException', 'RuntimePermission', 'SecurityException', > 'SecurityManager', 'Short', 'StackOverflowError', 'StrictMath', 'String', > 'StringBuffer', 'StringIndexOutOfBoundsException', 'System', 'Thread', > 'ThreadDeath', 'ThreadGroup', 'ThreadLocal', 'Throwable', 'UnknownError', > 'UnsatisfiedLinkError', 'UnsupportedClassVersionError', > 'UnsupportedOperationException', 'VerifyError', 'VirtualMachineError', > 'Void', '__name__', 'ref', 'reflect'] > c:\Document\Test> > > I am running on Windows 2000 with Sun's JDK 1.3.0. Have I miss some thing? > > I wrote this test file because I have develop a application and used the > interpreter in the debugging phase. Then I want to compile it before I send > it to external test. But when I compile it with Jythonc and try to run it > complain about a class in a java library don't exist. The std jython interpreter at initialitation time (for jars and dirs) and at runtime (for dirs) gathers info about java packages and the their classes (the info about jars is also cached), so a 'dir' correctly reports all classes in a package. The runtime when running jythonc compiled code does not gather such info (so to be on the safe side for the applet case), on the other hand the runtime needs to know java packages names to deals with imports properly: jythonc tries to gather the names of used packages when compiling the program (through a minimal form of partial evaluation) and store them in the produced classes but without the complete list of the classes in a package (this is not really needed and could be slightly different at execution time), so the empty 'dir' results (only actually imported classes will appear there). About the class not found problem: - a missing 'import' hint - the program was compiled under a classpath that does not contain all the classes needed at runtime, so jythonc fails to guess that something is actually a java package (yes, roughly jythonc should be executed with a classpath that offers all the classes that the program will need at runtime) - a problem with classloaders (these are hard to debug and one should knows what comes from where) ... and other possibilities that I don't remember . regards, Samuele Pedroni. |