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

查看:30
本文介绍了运行 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?

推荐答案

你是否有理由避免像

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天全站免登陆