[英]When running a java command with the -jar option, can you supply additional libraries using -cp?
When calling java command line using the -jar
option:使用
-jar
选项调用 java 命令行时:
java -jar connector-plugin-client.jar
Can you include additional libraries with -cp
?您可以使用
-cp
包含其他库吗?
java -jar connector-plugin-client.jar -cp ojdbc8.jar
I know I can do我知道我能做到
java -cp "connector-plugin-client.jar:ojdbc8.jar" the.main.MainClass
But wondering if that was necessary.但想知道是否有必要。
No, you cannot.你不能。 When using
-jar
, the class path is entirely defined by the jar itself and the Class-Path
entry in the META-INF/MANIFEST.MF
file inside the jar. It is not possible to add additional jars or directories to the class path using -cp
.使用
-jar
时,class 路径完全由 jar 本身和 jar 内的META-INF/MANIFEST.MF
文件中的Class-Path
条目定义。无法向 class 路径添加其他 jars 或目录-cp
。
In other words, -cp
and -jar
are mutually exclusive: you must choose one or the other.换句话说,
-cp
和-jar
是互斥的:您必须选择其中之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.