1

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?

1

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.