views:

3533

answers:

3

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.

A: 

You can create a big JAR which contains all related classes. The following ant snippet shows the idea:

<target name="jar">
 <mkdir dir="build/jar"/>
 <unjar src="lib/jython.jar" dest="${classes.dir}" />
 <unjar src="lib/FOO.jar" dest="${classes.dir}" />
 <unjar src="lib/BAR.jar" dest="${classes.dir}" />
 <unjar src="lib/BAZ.jar" dest="${classes.dir}" />

 <jar destfile="build/jar/bigjython.jar" basedir="${classes.dir}">
     <manifest>
         <attribute name="Main-Class" value="${main-class}"/>
     </manifest>
 </jar>
</target>
axelclk
Now how do I run my script using bigjython.jar?
Hank Gay
The bigjython.jar was meant to include the original jython.jar plus your extra jars. So at the end the bigjython jar should work the same as jython.jar but without the need of the -cp parameter.
axelclk
I'm not using jython.jar - I'm using `jython` command from the shell to execute argle.py
Hank Gay
A: 

See this also

rapto
+11  A: 

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

jython -Dpython.path=FOO:BAR:BAZ argyle.py

awithrow