运行java -jar时包含外部jar [英] include external jar when running java -jar

查看:279
本文介绍了运行java -jar时包含外部jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的阅读中,当您按如下方式执行命令时:

From my readings, when you execute a command as follows:

java -jar foo.jar

然后忽略主类路径,并从清单文件中获取类路径。

Then the main classpath is ignored, and the classpath is taken from the manifest file.

此外,命令行中声明的类路径也会被忽略。所以在:

Further, the classpath declared on the command line is also ignored. So in:

java -classpath /usr/local/jar/foobar.jar -jar foo.jar

/usr/local/jar/foobar.jar将被忽略。

/usr/local/jar/foobar.jar is ignored.

最后,我已经读过清单文件只能在jar文件中包含相对路径。

Lastly, I have read that the manifest file can only contain relative paths, within the jar file.

那么,如何包含外部jar的绝对路径,是否存在于系统中,但不存在于正在执行的jar文件中?

So, how do you include absolute paths to external jars, that are present on the system, but not in the jar file being executed?

推荐答案

您是否有理由避免调用主类如

Is there a reason why you are avoiding invoking the main class like

java -cp /usr/local/jar/foobar.jar:/some/other/path.jar com.your.main.classname

这种类型的调用允许您将绝对路径与相对路径混合。将它放入shell脚本或批处理文件中,以避免实际输入或记住完整的类路径以简化操作。

This type of invocation allows you to mix absolute paths with relative paths. Put this into a shell script or batch file to avoid having to actually type or remember the full classpath to simplify things.

这篇关于运行java -jar时包含外部jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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