Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use environment variables in a .properties or a xml file?

I am trying to configure my tomcat server.xml and I need to set value to something from an environment variable. I can't seem to find a way around from that.

I know how to use values stored in a properties file but I can't set a variable to use my environment variable in a property file as well. is there a work around? I tried the following:

1 - 
.xml file
<Resource
user="${VAR}"
.../> 
2 - 
<Resource
user="${env.VAR}"
.../> 
3 -
.properties file
myVar=${VAR} and then 
<Resource
user="${myVar}"
.../> 
like image 592
Peyush Goel Avatar asked Jan 25 '18 10:01

Peyush Goel


1 Answers

in my setenv.sh file

export JAVA_OPTS="$JAVA_OPTS -Dmyvar=${VAR}"

now I can use myvar inside a properties file or better, directly within a xml file since the variable is now available with tomcat context

<Resource
user="${myvar}"
.../>
like image 72
Peyush Goel Avatar answered Oct 25 '22 23:10

Peyush Goel