4

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!!

4

2 回答 2

4

在您的 shell 脚本中使用:

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

在我的情况下,设置CLASSPATH就足够了。请记住使用完整路径名并记住使用好的 .jar 名称(testmodule.jar并且TestModul.jar不同)。也许您使用了错误的文件权限。尝试file命令以检查您是否可以读取该文件。我使用的一个罐子的例子:

mn$ file junit-4.1.jar
junit-4.1.jar: Zip archive data, at least v2.0 to extract
于 2013-02-11T12:48:25.540 回答
3

我遇到了同样的问题。

我尝试了以下功能并且效果很好!

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

欲了解更多信息:

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

于 2013-10-24T20:30:40.920 回答