我如何在调用 Jython 时将 jar 添加到类路径中 *而无需*将它们添加到 $CLASSPATH 中? [英] How can I add jars to the classpath when I invoke Jython *without* adding them to $CLASSPATH?

查看:22
本文介绍了我如何在调用 Jython 时将 jar 添加到类路径中 *而无需*将它们添加到 $CLASSPATH 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些类似于 jython -cp FOO:BAR:BAZ argle.py 的事情.

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

如果我将 FOOBARBAZ 添加到 $CLASSPATH 这会起作用.我试图在运行时将它们添加到 sys.path 中,但这似乎不适用于 jars.如果我在运行时将扩展 jar 的路径添加到 sys.path,它确实可以工作.是否有一个简单的替代方法来爆炸 jar 文件?为每个运行此脚本的用户增加 $CLASSPATH 是不可接受的替代方法.

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.

谢谢.

推荐答案

你可以使用-D选项来设置python.path:

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

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

这篇关于我如何在调用 Jython 时将 jar 添加到类路径中 *而无需*将它们添加到 $CLASSPATH 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆