问题
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