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 |