Issue
I'm using OpenShift, and I'm trying to deploy my application to a local Tomcat instance for faster development. I'm using EclipseLink for DB transactions, and I've provided the environment variables OpenShift uses in persistence.xml like this:
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/mydbname"/>
<property name="javax.persistence.jdbc.user" value="${env.OPENSHIFT_MYSQL_DB_USERNAME}"/>
<property name="javax.persistence.jdbc.password" value="${env.OPENSHIFT_MYSQL_DB_PASSWORD}"/>
I'm using linux on my local machine, so I've set all of these variable values to the local versions as well (localhost, 3306, etc). I've double checked that they are available in terminal. I've also tried providing them like described here - I've opened the Tomcat instance's settings in Eclipse, chose "Open launch configuration", and on the Arguments tab, I've typed them into VM arguments (also tried the "Variables..." menu). However, it's not working, and I'm getting NumberFormatException on the PORT variable, I guess it takes the raw string "${env.OPENSHIFT_MYSQL_DB_PORT}" as port.
(Apparently, it's not working on OpenShift either.)
Where can I set these variable values in Eclipse/Tomcat to make it work?
Thank you in advance!
Solution
This is not possible. If you are using spring this can be possible there, but for simple JPA no. What you can do though is to use programmatic configuration and to do something like this described in this post Read Environment Variables in persistence.xml file
Answered By - Alexander Petrov
Answer Checked By - Marie Seifert (JavaFixing Admin)