From: Robert W. B. <rb...@di...> - 2001-10-26 21:25:13
|
Hello Matt, On Thu, 25 Oct 2001 Mat...@i2... wrote: > I'm having a problem loading python modules from a jar file. > I'm trying to package up the jython/Lib dir into a jar for use within an > embededded interpreter. > > If I jar up the contents of Lib into jython-lib.jar and add > "-Dpython.path=jython-lib.jar!Lib" to the launch of my app, it all works > fine. > If I first byte compile the contents of Lib and jar it up, that also works > fine. > However, if I jar up _just_ the byte compiled files in Lib, then I get > module import errors. > > Any idea what the problem is? I don't mind doing the second scenario so > long as someone can confirm that jython does in fact use the byte compiled > files and not the py files when they both exist in the jar. Thanks, > > Matt > mat...@i2... Jython's -v option allows you to trace the imports. Trying -v with your option #2 should show the *$py.class is used. The loadFromZip(jar)File actually does the same file time checking as it would from a dir to make sure the .py file isn't newer than the .class file, which makes loads from the jar fail without the .py files. I've wondered if this is necessary. Finn and Samuele have a better handle on that, but if you wanted to experiment with a *.py-less jar file the unified diff to do so is below. -robert ---------------------------------- --- jython/org/python/core/imp.java Fri Oct 26 16:20:15 2001 +++ imp.java Fri Oct 26 16:15:40 2001 @@ -308,24 +308,20 @@ ZipEntry pyEntry = zipArchive.getEntry(pyName); ZipEntry classEntry = zipArchive.getEntry(className); - if (pyEntry != null) { - Py.writeDebug("import", "trying source entry: " + pyName + - " from jar/zip file " + zipArchive); - if (classEntry != null) { - Py.writeDebug("import", "trying precompiled entry " + - className + " from jar/zip file " + - zipArchive); - long pyTime = pyEntry.getTime(); - long classTime = classEntry.getTime(); - if (classTime >= pyTime) { - InputStream is = zipArchive.getInputStream(classEntry); - o = createFromPyClass(modName, is, true, - classEntry.getName()); - if (o != null) { - return o; - } - } - } + Py.writeDebug("import", "trying source entry: " + pyName + + " from jar/zip file " + zipArchive); + if (classEntry != null) { + Py.writeDebug("import", "trying precompiled entry " + + className + " from jar/zip file " + + zipArchive); + InputStream is = zipArchive.getInputStream(classEntry); + o = createFromPyClass(modName, is, true, + classEntry.getName()); + if (o != null) { + return o; + } + } + if (pyEntry != null) { InputStream is = zipArchive.getInputStream(pyEntry); return createFromSource(modName, is, pyEntry.getName(), null); } |