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

后端 未结 4 1850
无人共我
无人共我 2020-12-12 18:50

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

If I add FOO, BAR, and BAZ to $CLASSP

相关标签:
4条回答
  • 2020-12-12 19:40

    jython command supports passing arguments through to the java command... So:

    jython -J-cp JAR1:JAR2
    

    You can verify the resulting command by adding --print switch:

    jython -J-cp JAR1:JAR2 --print
    

    The above will print out the actual java command instead of executing it.

    0 讨论(0)
  • 2020-12-12 19:41

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

    jython -Dpython.path=FOO:BAR:BAZ argyle.py
    
    0 讨论(0)
  • 2020-12-12 19:41

    java -cp JAR1:JAR2:jython.jar org.python.util.jython pythonScript.py works here, both on Linux and Macintosh. On Windows, swap the colons in the classpaths for semicolons and you should be golden.

    0 讨论(0)
  • 2020-12-12 19:41

    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>
    
    0 讨论(0)
提交回复
热议问题