Search code examples
xmlhibernatejpaeclipselinkpersistence

using JPA how to read .properties file in persistence file


How to read properties file in persistence.xml

I wanrt to read db user and password from a properties file for persistence.xml


Solution

  • Typically this kind of stuff is done by using build tools that manipulate setting files - like persistence.xml - by replacing needed parameters in that file before packaging.

    For example i use Maven and filtering in my java (mainly j2ee) projects to replace placeholders for persistence unit name or other needed project specific settings. Just because i like to keep all the configuration stuff in profiles and in one file.

    However this is an another topic and cannot be explained here briefly.