Title: package scanner doesn't look in Class-Path in the MANIFEST
Type: rfe Severity: normal
Components: Core Versions: Jython 2.7, Jython 2.5
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, fwierzbicki, jeff.allen, juha_rantanen
Priority: low Keywords: RFE

Created on 2007-08-21.11:55:42 by juha_rantanen, last changed 2018-11-04.16:53:34 by jeff.allen.

File name Uploaded Description Edit Remove
test.jar juha_rantanen, 2007-08-21.11:55:42 test.jar which contains the PackageTest class
msg1853 (view) Author: Juha Rantanen (juha_rantanen) Date: 2007-08-21.11:55:42
Importing with __import__() function fails with standalone jython.jar (2.2rc3). It works fine, when jython from the basic installation is used. Java version used was 1.4.2_13.

Following code was used to verify the problem.
    classname = 'PackageTest'
    module = __import__('some.pack.test')
    clazz = getattr(module, classname)
    clazz().print('__import__ successful!')
except Exception, e:
    print e
    from some.pack.test import PackageTest
    PackageTest().print('from import successful!')
package some.pack.test;

public class PackageTest {	

	public PackageTest(){
	public void print(String arg) {

When the is executed like:
"java -cp test.jar;jython.jar org.python.util.jython" and "java -jar jython.jar" The outcome is:
no module named some
from import successful!

In -jar case the test.jar (attached) was set to classpath by adding it to of jython.jar

So it seems that the package can be found from the environment, but the __import__ is not finding the package.
msg1854 (view) Author: Charlie Groves (cgroves) Date: 2007-09-25.05:06:10
The problem here is actually with Jython's package scanner.  To import packages directly, Jython needs to scan your jars at startup.  It can handle that with jars on -cp, but it doesn't have a way to find the jars included from the manifest file of a jar given with -jar.  Since it doesn't know what jars exist, it can't figure out what packages exist either.  

There are a few ways you can work around this.  If you import full Java classes, you won't need to worry about package scanning at all.  Replace __import__('some.pack.test') with __import__('some.pack.test.PackageTest') and that code should work.  Not relying on package scanning in Jython code has some advantages: the scanning takes some time so startup will be faster, and your code can run in restricted environments where jar scanning isn't possible.

You could also manually tell Jython where your jar is by adding it to sys.path.  Jars on sys.path are scanned when an import occurs.

Finally, you could write a patch for Jython's package scanner to tell it how to find jars from the manifest.  I'm not sure if jars from the manifest are made available to the JVM at runtime, so this may not be possible.  But if it is, it shouldn't be too difficult to add another hook into the package scanner to look for those jars and scan them automatically.
msg11837 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-21.22:26:17
I suggest this is a "won't fix", given the work-arounds and elapsed time.
Date User Action Args
2018-11-04 16:53:34jeff.allensetstatus: pending -> closed
2018-03-21 22:26:17jeff.allensetstatus: open -> pending
resolution: wont fix
messages: + msg11837
nosy: + jeff.allen
2013-02-27 16:37:10fwierzbickisetkeywords: + RFE
type: rfe
versions: + Jython 2.5, Jython 2.7
2009-03-14 02:54:44fwierzbickisetpriority: normal -> low
2008-12-15 15:45:56fwierzbickisetnosy: + fwierzbicki
components: + Core, - None
2007-08-21 11:55:42juha_rantanencreate