运行 java -jar 时包含外部 jar
根据我的阅读,当您执行如下命令时:
java -jar foo.jar
然后主类路径将被忽略,类路径将从清单文件中获取。
此外,在命令行上声明的类路径也会被忽略。所以在:
java -classpath /usr/local/jar/foobar.jar -jar foo.jar
/usr/local/jar/foobar.jar 中被忽略。
最后,我读到清单文件只能包含 jar 文件内的相对路径。
那么,如何包含系统上存在但不在正在执行的 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 is ignored.
Lastly, I have read that the manifest file can only contain relative paths, within the jar file.
So, how do you include absolute paths to external jars, that are present on the system, but not in the jar file being executed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否有理由避免调用主类
?
这种类型的调用允许您将绝对路径与相对路径混合。将其放入 shell 脚本或批处理文件中,以避免实际键入或记住完整的类路径以简化操作。
Is there a reason why you are avoiding invoking the main class like
?
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.
您可以在包含 jar 文件的文件夹中创建一个文件夹,例如 lib。
Manifest.MF 内容可以是:
文件夹内容:
要执行:
You can create a folder, say lib, within the folder where you have the jar file.
Manifest.MF contents can be:
Folder contents:
To execute: