0

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

Namy
  • 1
  • 1
  • From what I understand you want to write a shell script that will generate (or update) a Java property file and then launch the Java program. OK but, what's the content of the property file? what does `date -d tomorrow "+%Y-%m-%d"` have to do with it? – Fravadona Mar 23 '22 at 20:53
  • So basically I want job.date=2022-03-23 which i can get through date -d tomorrow "+%Y-%m-%d". But this works fine when job.date is accessed from shell script, but gives a parsing error when accessed from java class. Hope that clarifies – Namy Mar 23 '22 at 21:27

2 Answers2

0

You should use (if this is the property and value you want)

java -Djob.date=$(date -d tomorrow +"%Y-%m-%d") ...
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
0
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.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Namy
  • 1
  • 1