From: Samuele P. <pe...@in...> - 2001-09-12 18:27:03
|
Hi. The idea of the patch is fine for me, on the other hand it needs some work to better integrate with the rest of the import logic. In any case I would like to understand why so often jars are reported as bad, this should be quite rare... I think we should dig into that. regards, Samuele. > From: bc...@wo... (Finn Bock) > To: jyt...@li... > Subject: Re: [Jython-users] Simple java class import > X-BeenThere: jyt...@li... > X-Mailman-Version: 2.0.5 > List-Help: <mailto:jyt...@li...?subject=help> > List-Post: <mailto:jyt...@li...> > List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/jython-users>, <mailto:jyt...@li...?subject=subscribe> > List-Id: <jython-users.lists.sourceforge.net> > List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/jython-users>, <mailto:jyt...@li...?subject=unsubscribe> > List-Archive: <https://lists.sourceforge.net/archives//jython-users/> > X-Original-Date: Wed, 12 Sep 2001 18:16:09 GMT > Date: Wed, 12 Sep 2001 18:16:09 GMT > Mime-Version: 1.0 > > [Humbel Otmar] > > >Hello, > > > >when there is an 'invalid' .jar file in the classpath from where java can > >load classes, but from which the jython package manager cannot determine > >packages (other people have told us about similar problems with the jar > >utility here), I would nonetheless like to be able to import single java > >classes. > > > >The problem manifests as follows (package CH.obj.Libraries.Servlet lives > >inside the offending bisonInfra.jar): > > > > > >[appl|pwe] > jython > >*sys-package-mgr*: processing modified jar, 'E:\java\lib\bisonInfra.jar' > >*sys-package-mgr*: skipping bad jar, 'e:\java\lib\bisonInfra.jar' > >Jython 2.0 on java1.3.0 (JIT: null) > >Type "copyright", "credits" or "license" for more information. > >>>> from CH.obj.Libraries.Servlet import ServletSessionContext > >Traceback (innermost last): > > File "<console>", line 1, in ? > >ImportError: No module named Servlet > >>>> from java.lang import Class > >>>> clazz = Class.forName( "CH.obj.Libraries.Servlet.ServletSessionContext" > >) > >>>> clazz > ><jclass CH.obj.Libraries.Servlet.ServletSessionContext at 7698425> > >>>> > > > > > >For an 'intuitive' Jython user like me, there is no obvious reason why this > >import should fail ? > > I agree. > > >My motto is: Jython can import everything java can load ! > > I agree again. I hope you at least understand why importing java > packages fails. > > >With the following lines added just at the beginning of method importFromAs > > Please add this as a patch to the SF patch manager. That way we will not > forget it. > > >in org/python/core/imp.java (from the 2.0 codebase): > > > > public static void importFromAs(String mod, String[] names, String[] > >asnames, PyFrame frame) { > > if ( names.length==1 && asnames.length==names.length && > >asnames[0].equals(names[0]) ) { > > // this is a candidate for simple java class import > > String packageName = mod; > > String fullClassName = packageName + "." + names[0]; > > try { > > Class.forName( fullClassName ); > > PySystemState.add_package( packageName ); > > } catch( Throwable t ) {} > > } > > // rest of method left untouched > > // ... > > } > > > >the problem above would be solved. These lines do not at all claim to be > >perfect, they are thought just to show that it could be done: > > Of the top of my head, I kinda like it. It a pragmatic solution to a > huge problem which we (I fear) will never resolve perfectly. > > regards, > finn > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Humbel O. <Otm...@bi...> - 2001-09-13 14:35:49
|
[ Finn Bock ] > I agree again. I hope you at least understand why importing java > packages fails. Yes, of course. The 'what java can load' was meant for single java classes. > Please add this as a patch to the SF patch manager. That way=20 > we will not forget it. I hope patch #461151 is what you meant and need. > Of the top of my head, I kinda like it. It a pragmatic solution to a > huge problem which we (I fear) will never resolve perfectly. Pleased to hear that - thank you very much! May I ask a follow up:=20 When I use Jython as an embedded scripting language, the package manager will not scan the .jar files, I assume ? If so, there normally is the need for sys.add_package() in embedded scripts.=20 The suggested patch eliminates this need if java classes are imported explicitly ? Best wishes, Oti. |
From: Humbel O. <Otm...@bi...> - 2001-09-14 11:59:05
|
[ Samuele Pedroni ] > The idea of the patch is fine for me, on the other hand > it needs some work to better integrate with the rest > of the import logic. >=20 > In any case I would like to understand why so often > jars are reported as bad, this should be quite rare... >=20 > I think we should dig into that. Please let me try to describe the problem we have with our jar file. First at all, I think it is not a Jython issue. If java.util.Locale.getAvailableLocales() is called with this jar file in the classpath, we get: 'file IO Exception:java.util.zip.ZipException: invalid EXT descriptor signature' How do we create the jar file ? We start with a valid jar file named external.jar, which contains all the classes from packages we don't have the source code. external.jar for example contains: com.sun.mail javax.infobus oracle.jdbc etc. Each night we make our application, resulting in packages CH.obj.XYZ. Then we add these classes into a copy of external.jar (named bisonInfra.jar), and the result has the invalid EXT descriptor signature. We have tried every version of PKZIP and many different combination of classes in external.jar, always with the same result. Funny enough, the invalid EXT descriptor always occurs in the same package/class. I tend to blame PKZIP for that (but its only a guess), because if we do it manually (either with jar or WinZip): - unpack all directories from external.jar - adjust the upper/lower case of some directories (greetings from Windows) - pack the whole directory tree into an empty jar file the resulting jar is valid.=20 We simply can't do it right automatically. We test our classpath with the following script (snippet): # # scan the whole class path for .jar's and .zip's #=20 def testJarsOnClasspath( self ): # split the classpath into entries pathSep =3D System.getProperty( "path.separator" ) classpath =3D System.getProperty("java.class.path") pathEntries =3D string.split( classpath, pathSep ) # prepare the error dictionary self._errors =3D {} # test the files on classpath for pathEntry in pathEntries: suffix =3D pathEntry[-4:] if suffix =3D=3D ".jar" or suffix =3D=3D ".zip": self.__checkJarFile( pathEntry ) # report the errors if self._errors: message =3D "The following jar (or zip) files have errors: = \n" for jarFile in self._errors.keys(): message =3D "%s *** %s *** (in %s) \n" % (message, self._errors[jarFile], jarFile ) print message # # check a single jar file and add errors to self._errors #=20 def __checkJarFile( self, jarFilePath ): print "checking %s" % jarFilePath zipFile =3D ZipInputStream( FileInputStream( File(jarFilePath) ) ); try: entry =3D zipFile.getNextEntry() while entry !=3D None: if self._debug: print entry.getName() entry =3D zipFile.getNextEntry() except ZipException, ze: if self._debug: ze.printStackTrace() self._errors[ jarFilePath] =3D ze.getMessage() Best wishes, Oti. |
From: Samuele P. <pe...@in...> - 2001-09-17 23:06:34
|
[Humbel Otmar] > > Please let me try to describe the problem we have with our jar file. > First at all, I think it is not a Jython issue. If > java.util.Locale.getAvailableLocales() is called with this jar file in > the classpath, we get: > 'file IO Exception:java.util.zip.ZipException: invalid EXT > descriptor signature' > [snip] > > I tend to blame PKZIP for that (but its only a guess), because if we do Thanks for the report. No, the real problem is that sun didn't get the zip specification right or there are two "interpeprations" of it and took care of just one. To be honest the java.util.zip classes are a bit fragile, and with java 1.1 also have many bugs. But I don't think we will write our own versions ;( The moral: better use sun jar tool to create a jar to be used with java and jython. I don't remember the details but e.g. zipfile.py also seems to produce on some cases zips that java does not like. regards. |
From: Humbel O. <Otm...@bi...> - 2001-10-16 06:33:29
|
[Samuele Pedroni] > Thanks for the report. > No, the real problem is that sun didn't get the zip > specification right > or there are two "interpeprations" of it and took care of just one. <snip> Sorry for warming up cold coffee... But if I try to add another class file into the 'invalid' .jar file using WinZip, or if I try to delete a file from the .jar using WinZip, I get the following error log: """ Action: Add (and replace) files Include subfolders: no Save full path: no Include system and hidden files: yes Warning: extended local header not found for javax/infobus/ArrayAccess.class Error: Unsupported or invalid Zip file structure (E:\java\n_lib\bisonInfra.jar) """ This lets me think that maybe Sun is not fully at fault here. If it would be of some help, I could burn the .jar on CD and send it to you. Please let me know. (It is 16.6 MB so my mail system would reject it). Best wishes, Oti. |