I need to deploy a tomcat server setting the MySQL database url inside
/META-INF/config.properties
to the docker file. As we deploy these containers, IP addresses cannot be hardcoded in the program.
Is there any way to output environment variables from the system inside this file? I would like to do something like this:
mdms.db.url=jdbc:mysql://**${MYSQL_HOST}**/db_mdms?useEncoding=true&characterEncoding=UTF-8&autoReconnect=true mdms.db.username=root mdms.db.password=thesecretsauce
I searched the internet and found that I need to install some kind
-DMYSQL_HOST=$MYSQL_HOST
when starting the application, but starting tomcat with this flag did not do this trick, and I could not get it to work.
One more thing I tried:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="/WEB-INF/config.properties"/> <property name="ignoreResourceNotFound" value="true" /> <property name="searchSystemEnvironment" value="true" /> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> </bean>
although this does not seem to do the trick :(
I also tried both in combination with each other.
I am running Linux Xubuntu programming in Netbeans (although I figured out how to deploy tomcat without netbeans if necessary)
I am not the author of the application; and I'm not very sure about Tomcat / Java web applications. However, this needs to be done, and there is a language barrier (or rejection, I have not figured it out yet), preventing me from forcing the author to fix it for me.
Thanks for any help! -Paul