jython ImportError: No module named

喜你入骨 提交于 2019-12-22 14:59:25

问题


I'm new to jython and failing utterly at importing a java class within a jar.

What I am trying to do is write a wrapper shell script which calls a jython script. I can not allowed to edit the jython at all, so adding jars to sys.path within that jython script is not possible.

Error y", line 17, in from com.polarland.testModule.cache import CacheInterface ImportError: No module named polarland

I've added the jar which contains the above package with name of TestModule.jar to PATH, ClASSPATH and JYTHONPATH with no avail. I'm worried this is due to the name of the jar but am not sure.

Any advice would be greatly appreciated!!


回答1:


In your shell script use:

export CLASSPATH=TestModule.jar:$CLASSPATH
jython ...

In my case setting CLASSPATH is enough. Remember to use full path name and remember to use good .jar name (testmodule.jar and TestModul.jar are different). Maybe you use wrong file rights. Try file command to check if you can read that file. Example for one of jars I use:

mn$ file junit-4.1.jar
junit-4.1.jar: Zip archive data, at least v2.0 to extract



回答2:


I was getting same issue.

I tried below function and worked well!

>>> import sys 
>>> sys.path.append('/path/to/helloworld.jar')
>>> from com.leosoto import HelloWorld

For more info:

http://blog.leosoto.com/2008/07/jython-import-logic.html



来源:https://stackoverflow.com/questions/14754402/jython-importerror-no-module-named

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