Reputation: 5720
I have executable jar file with its main class being specified in META-INF/MANIFEST.MF
and one some of the properties specified in config.properties
and folder/config.properties
.
So the structure of my jar file is
./my-jar-with-dependencies.jar
|- com/mypackage/Main.class
|- META_INF/MANIFEST.MF
|- config.properties
|- folder
| |- config.properties
| - system.properties
|- lib
|
..
What I want to achieve is execute the jar file as java -jar my-jar-with-dependencies.jar -Dconfig.properties=\path\to\new\config.properties_outside_the_jar
and overriding the properties file within the jar.
Is this possible? If so how?
Note: I am not the one in control of how the jar is packaged, so changing the packaging of jar is not really an easy option
Upvotes: 1
Views: 4368
Reputation: 691765
Just put a directory containing the properties files, with the same package structure, in the classpath, before the jar file:
./my-config-directory
|- config.properties
|- folder
|- config.properties
- system.properties
And use
java -cp ./my-config-directory:my-jar-with-dependencies.jar:dependency1.jar:dependency2.jar com.mypackage.Main
Note that a jar file is just a zip file. So you could also just unzip the jar file, replace the properties files, and zip again.
Upvotes: 4