I want to be able to store my database information in a pom.xml (as properties) and inject the necessary values into my persistence.xml file. Is there any way I can achieve this in maven?
an alternative would be how to keep my database connection information in one file and be able to feed it to both my pom.xml and my persistence.xml
xml , choose the Source tab. Specify the data source for the persistence unit. Typically, you use the relevant data source alias name to specify the DataSource. Make sure that the value of the jta-data-source tag is the same as the value of the alias tag in the data-source-aliases.
Procedure. In the Package Explorer view, right-click the persistence. xml file of the JPA project that you want to edit and select Open with > Persistence XML Editor. In the Design tab of the Persistence XML Editor, make any of the following changes to the persistence.
xml File. This file is used to override the default Hibernate settings and to add support for database types that are not out of the box (OOB database types are Oracle Server, Microsoft SQL Server, and MySQL).
xml files. Have multiple persistence units in one persistence.
You can locate your persistence.xml into a a location like src/main/resources/PATH and use the filtering option to filter your persistence.xml and put into the correct location. This can be achieved by activating the filtering in resources like this:
<resource>
<directory>src/main/resources/PATH</directory>
<filtering>true</filtering>
</resource>
The same for your test resources:
<testResources>
<testResource>
<directory>src/main/resources/PATH</directory>
<filtering>true</filtering>
</testResource>
</testResources>
Based on the above you can give things like this 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 (i can remember something like META-INF/.. ? If yes that put it into src/main/resources/META-INF and change the filter directory accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With