Using your own class loader is the right technique for this case. Any such classes that are loaded will properly work as if you imported them through Jython, used Java reflection, or simply were passed a reference to them. Jython doesn't look at class name, but identity on the Class object when mapping its Python types (proxies) to Java classes.

Lastly, we used to maintain strong references from such proxies in our canonical mapping, which was the underlying bug inĀ, but as of 2.5.2 beta 1, the mapping has been weakened. This means that such classes can be garbage collected. This is particularly important to avoid permgen exhaustion on JVMs that use that approach.

- Jim

On Thu, Aug 12, 2010 at 3:15 PM, Brandon Pedersen <> wrote:
Just wanted to note, this worked perfectly for what I needed. I was
actually trying to dynamically determine which version of the jar I
needed to add to sys.path and this way I could check both jar file
contents without messing with the package manager until I needed to
add one of them to sys.path



On Thu, Aug 12, 2010 at 12:19 PM, Brandon Pedersen <> wrote:
> On Thu, Aug 12, 2010 at 11:00 AM, Leinartas, Michael
> <> wrote:
>> What I ended up doing was to make my own ClassLoader and manually load the
>> classes.
>> jarUrls = [File(jar).toURL() for jar in jars]
>> myclassloader = URLClassLoader(jarUrls, ClassLoader.getSystemClassLoader())
>> myClass = myclassloader.loadClass('org.myorg.myclass')
> Great, I will give this a try
>> ...
>> I actually dont have any need in my code to instantiate anything so ymmv
>> with that.
> This may actually just work for what I need
>> One thing I started to try but didnt end up pursuing was to fiddle with the
>> system classloader
>> With your classloader above, you can:
>> sys.setClassLoader(myclassloader)
>> and then import classes from it. The thing I never figured out was how to
>> clear the import cache so that I could re-import after changing the
>> ClassLoader another time.
> You can try starting jython with the system property
> python.cachedir.skip set to true which will disable caching
> -Brandon

This email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
Jython-users mailing list