Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add jars to the classpath when I invoke Jython *without* adding them to $CLASSPATH?

I'd like to do something similar to jython -cp FOO:BAR:BAZ argle.py.

If I add FOO, BAR, and BAZ to $CLASSPATH this works. I tried to add them to sys.path at run-time, but that doesn't appear to work for jars. It does work if I add a path to the expanded jars to sys.path at runtime. Is there a simple alternative to exploding the jar files? Augmenting $CLASSPATH for every user that runs this script is not an acceptable alternative.

Thanks.

like image 697
Hank Gay Avatar asked Feb 11 '09 16:02

Hank Gay


People also ask

How do I know if a jar is classpath?

A pragmatic way: Class. forName("com. myclass") where com. myclass is a class that is inside (and only inside) your target jar; if that throws a ClassNotFoundException , then the jar is not on you current classpath.


1 Answers

You can use the -D option to set python.path:

jython -Dpython.path=FOO:BAR:BAZ argyle.py 
like image 94
awithrow Avatar answered Oct 04 '22 17:10

awithrow