The import semantics do not differ that much from CPython
s from what I see in the Jython Docs
.
First a search is made for the .jar
file in the current directory; if it is not found there, it is looked up in the directory containing the core Jython
libraries. The classpath
which corresponds to Java
s CLASSPATH
is then searched along with the site-packages
directory containing external libaries. I am not yet sure what __pyclasspath__
is.
So if a package is not found in those directories an import error is raised. You have two options:
- Either add the
.jar
in one of the directories (typically you should never add it to the directory containing the core libs.
- Add the
.jar
to your CLASSPATH
.
- Add the path to your
.jar
in sys.path
.
For the first case, either move it to the current direcory or in site-packages
.
For the second case see here on how to add a .jar
to your CLASSPATH
.
For the third simply call sys.path.append("path_to_jar")
to include the directory containing your .jar
file to sys.path
.