简体   繁体   English

使用 -jar 选项运行 java 命令时,您可以使用 -cp 提供额外的库吗?

[英]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.

相关问题 Java与jar一起运行时不遵循-cp选项的类路径规范 - Java not honoring the classpath specification with -cp option when running with a jar 在jar文件中使用java -cp时出错 - Error when using java -cp with jar file 为什么 Java -cp 选项在使用 spring-boot-maven-plugin 时 -jar 不起作用? - Why is the Java -cp option not working when -jar does while using the spring-boot-maven-plugin? 线程“ main”中的异常java.io.FileNotFoundException:使用java -cp命令运行Maven项目时 - Exception in thread “main” java.io.FileNotFoundException: when running maven project using java -cp command 运行应用程序时,如何传递Java命令执行的附加jar? - How do I pass an additional jar do my java command when running application? Java 一起使用“-cp”和“-jar” - Java using “-cp” and “-jar” together 使用命令提示符的可运行jar的附加调试选项 - Additional debug option for runnable jar using command prompt 在命令提示符下运行jar文件。 Java无法在类路径中找到库 - Running jar file in command prompt. Java can't find libraries in classpath 通过命令行创建可运行的.jar时,添加其他.jar库 - Add additional .jar libraries when creating a runnable .jar via command line 运行jar时从命令行(java -cp)在应用程序内使用属性 - Use property within application from command line (java -cp) while running jar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM