简体   繁体   English

Java 用命令行覆盖依赖

[英]Java override dependency with command line

i'am building a jarfile whith maven.我正在用 maven 构建一个 jarfile。 my question is,how to override a dependency with command line during jar execution.我的问题是,如何在 jar 执行期间使用命令行覆盖依赖项。

here is my command line这是我的命令行

java -Djava.library.path="C:\Users\param" -jar Test-1.0-SNAPSHOT-jar-with-dependencies.jar java -Djava.library.path="C:\Users\param" -jar Test-1.0-SNAPSHOT-jar-with-dependencies.jar

thanks谢谢

You can't.你不能。 When using the -jar option, the class path is controlled by the Class-Path entry in the manifest, and you cannot change it.使用-jar选项时,class 路径由清单中的Class-Path条目控制,您无法更改它。 The only ways to change it while still using -jar is by either modifying the manifest, or replacing the jar file referenced by the manfifest.在仍然使用-jar的同时更改它的唯一方法是修改清单或替换清单引用的 jar 文件。

Another alternative is to not use -jar , but instead use -cp to specify the class path (you will need to specify all dependencies yourself,).另一种选择是不使用-jar ,而是使用-cp指定 class 路径(您需要自己指定所有依赖项)。 and explicitly specify the main class.并明确指定主类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM