'Getting a date in properties file in string format
I want to get a date from a key dynamically which will be used by java program to perform some tasks.
I have to get values from property file to java. cannot do vice versa
So basically the value for this key, job.date=2022-03-23 i can get through date -d tomorrow "+%Y-%m-%d". But this works fine when job.date is accessed from shell script and gives a parsing error when accessed from java class.
so looking for java understandable snippet, or a way to override it while executing the java class with jar
Solution 1:[1]
You should use (if this is the property and value you want)
java -Djob.date=$(date -d tomorrow +"%Y-%m-%d") ...
Solution 2:[2]
java -Djob.date=$(date -d tomorrow +"%Y-%m-%d") ...
The above gave me exception, error loading main class.
It worked with following snippet:
sed -i "s/\(testauto\.as\.of\.date=\).*\$/\1${tomorrow}/" abc.properties
Added this line in shell script that was calling the java class.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Diego Torres Milano |
| Solution 2 | Tyler2P |
