Arezki
Arezki

Reputation: 35

Java override dependency with command line

I am building a jarfile with maven.

My question is: how to override a dependency with command line during jar execution?

Here is my command line

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

Thanks

Upvotes: 0

Views: 385

Answers (1)

Mark Rotteveel
Mark Rotteveel

Reputation: 108994

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. 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.

Another alternative is to not use -jar, but instead use -cp to specify the class path (you will need to specify all dependencies yourself!), and explicitly specify the main class.

Upvotes: 1

Related Questions