Author rec
Recipients rec
Date 2014-05-13.09:04:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It appears to be a common and good practice to set the context classloader of the current thread when entering a context that offers access to new classes, e.g. in Jython via the syspath. 

E.g. the Spring framework does its class/resource lookup by taking the context classloader into account if it is set. The Groovy language sets the context classloader when entering into a Groovy context.

Such a behaviour can allow Java code invoked from within the Jython context access to classes/resources available through the syspath.

Our concrete use-case is that we build Jython scripts that use jip [1] to dynamically download and add Maven dependencies, e.g.:

  from org.apache.commons.lang import StringUtils

We do not only access classes from such dependencies in Jython, but e.g. access them via reflection from Java code invoked via Jython or access resources stored in such JARs from Java code invoked via Jython (e.g. via Spring).

To make this work, we currently need to add the following line to the beginning of each script

  Thread.currentThread().contextClassLoader = getSyspathJavaLoader()

It would be great if Jython did set/restore the context classloader automatically when entering the Jython context, so that we do not have to do this manually.

Date User Action Args
2014-05-13 09:04:19recsetrecipients: + rec
2014-05-13 09:04:19recsetmessageid: <>
2014-05-13 09:04:18reclinkissue2142 messages
2014-05-13 09:04:18reccreate