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. |
From: Samuele P. <pe...@in...> - 2001-05-22 09:01:18
|
Hi. Seems that a lot of people ignore this but java -jar does not use the classpath settings, the jar should be self-contained. This is unrelated to jython <wink> (on the other hand - I think - extensions (in java sense) are considered) http://java.sun.com/j2se/1.3/docs/tooldocs/linux/java.html#-jar regards. |
From: Frode R. <fro...@er...> - 2001-05-21 21:37:29
|
Hi again, I try with a new example and below you can see the log. I am using Jython2.1a1. If I remove the from ... Import then I get a "AtributeError java package 'datarep.common' has no attribute 'Spacer'". If someone want to try with the datarep_common.jar you can either download Simplicity or send me a mail so I can send it off list. ============ Log start ============ c:\Document\PaaceTest>type test.py type test.py import java,javax,datarep.common from datarep.common import Spacer class testClass: def __init__(self): self.Spacer = datarep.common.Spacer(5,5) t=testClass() print t.Spacer c:\Document\PaaceTest>jython test.py jython test.py datarep.common.Spacer[,0,0,5x5,invalid] c:\Document\PaaceTest>java -jar test.jar -c test.py java -jar test.jar -c test.py Java Traceback: at org.python.core.Py.ImportError(Py.java:180) at org.python.core.imp.importFromAs(imp.java:593) at test$_PyInner.main$3(test.java:61) at test$_PyInner.call_function(test.java:38) at org.python.core.PyTableCode.call(PyTableCode.java:198) at org.python.core.PyCode.call(PyCode.java:13) at org.python.core.imp.createFromCode(imp.java:165) at org.python.core.Py.runMain(Py.java:818) at test.main(test.java:80) Traceback (innermost last): File "C:\Document\PaaceTest\test.py", line 0, in main ImportError: cannot import name Spacer c:\Document\PaaceTest>jythonc -jar test.jar -c test.py jythonc -jar test.jar -c test.py Warning: -jar is deprecated, use --jar processing test Required packages: javax java datarep.common Creating adapters: Creating .java files: test module Compiling .java to .class... Compiling with args: ['c:\\tools\\jdk130\\bin\\javac', '-classpath', '"C:\\tools\\Jython\\Jython21a1\\jython.jar;.;C:\\tools\\SimplicityProfessio nal\\pbclient31RE.jar;C:\\tools\\SimplicityProfessional\\pbnetwork31RE.jar;C :\\tools\\SimplicityProfessional\\datarep_common.jar;.\\jpywork;;C:\\tools\\ Jython\\Jython21a1\\Tools\\jythonc;c:\\Document\\PaaceTest\\.;C:\\tools\\Jyt hon\\Jython21a1\\Lib;C:\\tools\\Jython\\Jython21a1"', '.\\jpywork\\test.java'] 0 Note: Some input files use or override a deprecated API. Note: Recompile with -deprecation for details. Building archive: test.jar Tracking java dependencies: c:\Document\PaaceTest>java -jar test.jar test java -jar test.jar test Java Traceback: at org.python.core.Py.ImportError(Py.java:180) at org.python.core.imp.importFromAs(imp.java:593) at test$_PyInner.main$3(test.java:57) at test$_PyInner.call_function(test.java:36) at org.python.core.PyTableCode.call(PyTableCode.java:198) at org.python.core.PyCode.call(PyCode.java:13) at org.python.core.imp.createFromCode(imp.java:165) at org.python.core.Py.runMain(Py.java:818) at test.main(test.java:74) Traceback (innermost last): File "C:\Document\PaaceTest\test.py", line 0, in main ImportError: cannot import name Spacer c:\Document\PaaceTest>jar -tf c:\tools\SimplicityProfessional\datarep_common.jar jar -tf c:\tools\SimplicityProfessional\datarep_common.jar META-INF/MANIFEST.MF datarep/ datarep/common/ datarep/common/AbsoluteLayout.class datarep/common/ApplicationAudioClip.class datarep/common/BottomLayout.class datarep/common/Calculator.class datarep/common/Calculator$Lexer.class datarep/common/Calculator$Cpu.class datarep/common/CalculatorTest.class datarep/common/CloseListener.class datarep/common/Email.class datarep/common/Flyer.class datarep/common/FlyoutHelpManager.class datarep/common/FrameAnimator.class datarep/common/GBConstraints.class datarep/common/GroupBoxPanel.class datarep/common/HeavyGroupBoxPanel.class datarep/common/Helpable.class datarep/common/HelpTest.class datarep/common/ImageButton.class datarep/common/ImageCanvas.class datarep/common/ImageHandler.class datarep/common/JarUtil.class datarep/common/LeftSideLayout.class datarep/common/MessageBox.class datarep/common/ProgressBar.class datarep/common/Sizer.class datarep/common/Spacer.class datarep/common/TabbedCardPanel.class datarep/common/TemplateProcessor.class datarep/common/TemplateProcessor$Node.class datarep/common/TextPrinter.class datarep/common/Util.class datarep/common/ValidatedTextField.class datarep/common/WrapLabel.class datarep/common/database/ datarep/common/database/QueryTableModel.class datarep/common/database/QueryListModel.class datarep/common/database/QueryComboBoxModel.class datarep/common/database/ColumnMapping.class datarep/common/database/InputMapping.class datarep/common/database/ActionMapping.class datarep/common/database/SelectionMapping.class datarep/common/database/Mapping.class datarep/common/database/Query.class datarep/common/database/QueryList.class datarep/common/database/Command.class datarep/common/database/DatabaseManager.class datarep/common/database/DatabaseManager$SelectionCommandListener.class datarep/common/database/DatabaseManager$ActionCommandListener.class c:\Document\PaaceTest>echo %classpath% echo %classpath% .;C:\tools\SimplicityProfessional\pbclient31RE.jar;C:\tools\SimplicityProfes sional\pbnetwork31RE.jar;C:\tools\SimplicityProfessional\datarep_common.jar c:\Document\PaaceTest> ============ Log end ============ > 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. : : First example removed because Samuele Pedroni explain it. : >> 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. > |