Is it possible to enter values ​​into persistence.xml from maven?

I want to be able to store information about my database in a pom.xml file (as properties) and insert the necessary values ​​into my persistence.xml file. Is there any way to achieve this in maven?

an alternative would be how to save the database connection information in one file and be able to submit it both to my pom.xml and to my persistence.xml

+6
source share
1 answer

You can find your persistence.xml as a location, for example src / main / resources / PATH, and use the filter option to filter your persistence.xml and paste into the correct location. This can be achieved by activating filtering in resources such as this:

<resource> <directory>src/main/resources/PATH</directory> <filtering>true</filtering> </resource> 

The same goes for your test resources:

 <testResources> <testResource> <directory>src/main/resources/PATH</directory> <filtering>true</filtering> </testResource> </testResources> 

Based on the above, you can pass such things in your persistence.xml

  <hibernate.url>${database.url}</hibernate.url> 

What you need to check is the correct target location of the persistence.xml file (can I recall something like META-INF / ..? If so, put it in src / main / resources / META-INF and change accordingly.

+10
source

Source: https://habr.com/ru/post/916266/


All Articles