jython 中的类导入
我有一个 jython 脚本,需要包含一个类(在本例中来自 JUnit)。我在“some/path/junit.jar”中有 junit jar。我的脚本是:
from junit.textui import TestRunner
TestRunner.Main(["name of some class here"])
我像这样运行它:
java -cp "some/path/junit.jar" -jar jython.jar script.py
但它抱怨:
from junit.textui import TestRunner
ImportError: No module named junit
我怎样才能让它看到/导入正确的类?
I've got a jython script that needs to include a class (from JUnit in this case). I've got the junit jar in "some/path/junit.jar". My script is:
from junit.textui import TestRunner
TestRunner.Main(["name of some class here"])
I'm running it like this:
java -cp "some/path/junit.jar" -jar jython.jar script.py
but it complains that:
from junit.textui import TestRunner
ImportError: No module named junit
How can I make it see/import the correct class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 -jar 选项时,java 会忽略类路径。像这样直接运行jython类,
你必须喜欢他们的命名约定(所有小写的类名)。我假设类名称为 Jython,我尝试了几次才弄清楚这一点。
When you use -jar option, java ignores classpath. Just run jython class directly like this,
You have to love their naming convention (all lower-case class name). I assumed the class name would be Jython and it took me a few tries to figure this out.
作为 ZZ Coder 答案的一个可能更简单的替代方案,您还可以在 Jython 的启动脚本上使用 -J-cp 参数:(
我会将其作为注释附加到前一个答案中,但我的声誉还不允许这样做。 )
As a - maybe simpler - alternative to ZZ Coder's answer, you can also use the -J-cp parameter on Jython's start script:
(I would have appended this as a comment to the former answer, but my reputation does not allow it yet.)