Import jar API in Jython

五迷三道 提交于 2019-12-07 03:18:25

问题


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?


回答1:


You need to provide the full path of the JAR file. Change

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

to

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



回答2:


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")


来源:https://stackoverflow.com/questions/11693993/import-jar-api-in-jython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!