How can I add jars dynamically to jython, inside script?
Asked 07 September, 2021
Viewed 1.7K times
  • 59
Votes

I am writing a package in python that talks to an ldap server. I want it to work in CPython and Jython. To get it to work with CPython, I have successfully coded against python-ldap. However, to get it working with Jython, I must use a java jar.

How can I distribute the jar file with my package, so that if it can "import java", it knows its jython, and dynamically adds the java jar to the path, and utilizies it. However, if that fails, it knows its CPython and uses the python-ldap libraries.

Any ideas?

1 Answer