importjarjython

Import jar API in Jython


I am trying to import a Java API, which is distributed as a jar file. I followed the instructions from this answer at a similar question in Stack Overflow, but it didn't work.

In Jython, I did:

>>> import sys
>>> sys.path.append("/path/to/jar/api")
>>> from com.thingmagic import *
Traceback (most recent calls last):
  File "<stdin>", line 1, in <module>
ImportError: no module named thingmagic

Am I missing something or did I do something wrong?


Solution

  • The problem was that I was using only one backslash on the path (I'm developing on Windows), instead of two:

    sys.path.append("C:\\remember\\to\\use\\two\\backaslashes\\jarName.jar")