Message8388

Author rec
Recipients rec
Date 2014-05-13.09:04:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1399971859.09.0.208143021037.issue2142@psf.upfronthosting.co.za>
In-reply-to
Content
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.:

  require('commons-lang:commons-lang:2.6')
  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.

[1] https://pypi.python.org/pypi/jip
History
Date User Action Args
2014-05-13 09:04:19recsetrecipients: + rec
2014-05-13 09:04:19recsetmessageid: <1399971859.09.0.208143021037.issue2142@psf.upfronthosting.co.za>
2014-05-13 09:04:18reclinkissue2142 messages
2014-05-13 09:04:18reccreate