Question

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?

Was it helpful?

Solution

When you use -jar option, java ignores classpath. Just run jython class directly like this,

java -cp "some/path/junit.jar:some/other/path/jython.jar" org.python.util.jython script.py

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.

OTHER TIPS

As a - maybe simpler - alternative to ZZ Coder's answer, you can also use the -J-cp parameter on Jython's start script:

    jython -J-cp "some/path/junit.jar" script.py

(I would have appended this as a comment to the former answer, but my reputation does not allow it yet.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top