Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Jar file with external properties

Tags:

java

jvm

java-8

jar

I have jar file that I want to run along with specific properties file. I am running following command to execute that jar

java –jar –DApp.config.file=local.properties App.jar

With this command I am getting following error

Could not load properties from class path resource [local.properties]: class path resource [local.properties] cannot be opened because it does not exist

Based on what I read so far if you are passing -jar then you don't have to worry about $CLASSPATH. Am I missing something here ?

PS - local.properties and jar files are in same directory.

like image 700
slonkar Avatar asked Oct 17 '25 15:10

slonkar


2 Answers

The -jar option specifies the jar file to launch, hence, has to remain right before the naming of the intended jar file:

java –DApp.config.file=local.properties –jar App.jar

Don’t place other options between –jar and App.jar

like image 91
Holger Avatar answered Oct 20 '25 04:10

Holger


You can use the following snipped to access external properties file and run your jar file:

java -jar jarname.jar --spring.config.location=/path/to/propertyfile.properties
like image 24
Amrutha Avatar answered Oct 20 '25 04:10

Amrutha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!