Dear Chris,

 Cant tell you an answer about version 2.5 2, indeed my development machine also runs on an older Jython Version
2.5.1.

The  Java  classPathHacker  routine is unrelated to the Jython book, as I've ported it from from a Java code fix.  
Might be the same origin, really not sure. I suggest your to give it trial, as it works O.K. here, I even used this patch for  

a Jython stand-alone installer  running with java -jar and all libraries are fetched correctly by the Jython interpreter.

The solution shown on the  http://glasblog.1durch0.de/?p=846  looks similar, should also work OK. Thanks for
sharing this alternate  classPathHacker  solution.  

Regards,
Claude  


Claude Falbriard
Certified IT Specialist L2 - Middleware
AMS Hortolāndia / SP - Brazil
phone:    +55 13 9762 4094
cell:         +55 13 8117 3316
e-mail:    claudef@br.ibm.com



From:        Chris Clark <Chris.Clark@ingres.com>
To:        Claude Falbriard/Brazil/IBM@IBMBR
Cc:        jython-users@lists.sourceforge.net
Date:        05/05/2011 17:52
Subject:        Re: [Jython-users] Classloader trouble / A sample of a dynamic class loader for Java




Does this work with Jython 2.5.2 (I'm not on a machine where I can
test)? This looks similar to the code in the JythonBook which I reported
as not working with 2.5.3 in March.

I've been using
http://glasblog.1durch0.de/?p=846 instead.

Chris


claudef@br.ibm.com wrote:
> Dear Konrad,
>
>  Not sure if this post is  somehow related with your problem. Just
> want to share a solution how I use to handle customized ClassLoaders
> in Jython.  
>
>  With this technique shown below I've successfully patched a few
> CLASSPATH  problems when loading open source Java packages. Many Java
> classes read the CLASSPATH  definition set at the start-up of the Java
> JVM, its value is immutable ( the behavior is Java and not Jython !).
>  Object serialization is another problem point when it comes to Java
> class loaders ..  
>
> Here the Java patch to set the CLASSPATH dynamically (ported to Jython):
>
> import java.lang.reflect.Method
> from java.io import File as javaFile
> from java.net import URL
> from java.net import URLClassLoader
> from java.lang import Class as javaClass
> from java.lang import ClassLoader as javaClassLoader
> from java.lang import Object as javaObject
> from java.lang import System
> import jarray
>
> class classPathHacker():
>        
>     def __init__(self):
>         # init actions
>         self.DEBUG = 0                
>         pass        
>
>     def addURL (self, u):
>             DEBUG = 0    
>         ##################################
>         # Purpose: Call this with u= URL for
>         #       the new Class/jar to be loaded
>         #################################  
>         parameters = jarray.array([URL], javaClass)
>         sysloader =  javaClassLoader.getSystemClassLoader()
>         sysclass = URLClassLoader
>         method = sysclass.getDeclaredMethod("addURL", parameters)
>         a = method.setAccessible(1)
>         jar_a = jarray.array([u], javaObject)
>         if DEBUG: print ("jar added is : " + str(jar_a))
>         b = method.invoke(sysloader, jar_a)
>         sysProp = System.getProperties()
>         if DEBUG: print ("------- Resulting CLASSPATH modified by
> classPathHacker-------" + "\n")
>         if DEBUG: print (sysProp.getProperty("java.class.path"))
>         return u
>        
>     def addFile (self, s):
>         #############################################
>         # Purpose: If adding a file/jar call this first
>         #       with s = path_to_jar
>         #############################################
>         # make a URL out of 's'
>         f = javaFile(s)
>         u = f.toURL()
>         a = self.addURL(u)
>         return a        
>        
>     if __name__ == "__main__":
>             DEBUG = 0    
>         if DEBUG: print "callPathHacker is active"
>
>
> Inside my Jython projects, I use to add  the python path, like this
> and in a second step fix the CLASSPATH for Java:
>
> # import customized class loader
> import sys
> import classPathHacker
> from java.lang import *
> sysProp = System.getProperties()
> userdir = sysProp.getProperty("user.dir")
> userdir = userdir.replace("\\", "/")  
> sys.path.append(userdir + "/package_name.jar")
> # ...
> try:
>    # dynamically adds CLASSPATH for Java Class Loader        
>    jarLoad = classPathHacker.classPathHacker()
>    url_a = jarLoad.addFile(userdir + "/packageA/package_name.jar")
>    url_b = jarLoad.addFile(userdir + "/packageB/package_name.jar")  
> except Exception, e:
>    print ("ClassPathHacker Load .jar Error:" + str(e))
>
>
> The combination of both technique use to handle most of the class
> loader situations under Jython 2.5.
>
> Hope, this is useful.
>
> Regards,
> Claude
>
>  
> *
> Claude Falbriard
> Certified IT Specialist L2 - Middleware
> AMS Hortolāndia / SP - Brazil
> phone:    +55 13 9762 4094
> cell:         +55 13 8117 3316
> e-mail:    claudef@br.ibm.com
> *
>
>
>
> From:        Konrad Hinsen <konrad.hinsen@fastmail.net>
> To:        jython-users@lists.sourceforge.net
> Date:        05/05/2011 13:52
> Subject:        [Jython-users] Classloader trouble
> ------------------------------------------------------------------------
>
>
>
> I am running into a problem that has been discussed before here, but I
> can't find any satisfying answer, so I try again.
>
> I run Jython from inside a framework that defines its own custom
> classloaders. What it does is
> 1) Create a custom classloader with the Jython standalone jar in its
> classpath (among other stuff).
> 2) Set this classloader to be the context classloader of the current
> thread.
> 3) Load org.python.util.jython using the same custom classloader.
> 4) Invoke its main method.
> This should ensure that the custom classloader is both the current
> classloader and the thread's context classloader. I would expect
> Jython to use or delegate to at least one of these, but apparently it
> doesn't.
>
> This fires up the Jython console which works just fine, as long as I
> use only Python modules and the standard Java packages. But I have no
> access to the other stuff that is handled by the custom class loader
> that was used to launch Jython. Indeed, I have verified that Jython
> never uses this class loader once the interpreter is up and running.
>
> I checked org.python.core.imp.getClassLoader(), and I do get my custom
> classloader back. That looks fine. But why is this classloader never
> used? And what is used instead?
>
> Since various posts on this subject mention sys.setClassLoader(), I
> tried this as well:
>
>                 sys.setClassLoader(org.python.core.imp.getClassLoader())
>
> But this doesn't help, my classloader is still not used.
>
> Does anyone have ideas or pointers to useful information?
>
> Thanks in advance,
>  Konrad.
>
>
> ------------------------------------------------------------------------------
> WhatsUp Gold - Download Free Network Management Software
> The most intuitive, comprehensive, and cost-effective network
> management toolset available today.  Delivers lowest initial
> acquisition cost and overall TCO of any competing solution.
>
http://p.sf.net/sfu/whatsupgold-sd
> _______________________________________________
> Jython-users mailing list
> Jython-users@lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/jython-users
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> WhatsUp Gold - Download Free Network Management Software
> The most intuitive, comprehensive, and cost-effective network
> management toolset available today.  Delivers lowest initial
> acquisition cost and overall TCO of any competing solution.
>
http://p.sf.net/sfu/whatsupgold-sd
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jython-users mailing list
> Jython-users@lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/jython-users
>  


------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users