Import jar API in Jython

I am trying to import a Java API that is distributed as a jar file. I followed the instructions of this answer on a similar question in Stack Overflow, but that 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 something wrong?

+4
source share
2 answers

The problem was that I used only one backslash in the path (I am developing on Windows) instead of two:

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

You need to specify the full path to the JAR file. The change

 sys.path.append("/path/to/jar/api") 

to

 sys.path.append("/path/to/jar/api/whatever_the_name_is.jar") 
+11
source

All Articles