Search code examples
maven-2jpamavenpersistence.xml

Combine two or more persistence.xml(s) into one, when packaging (war) many modules (Maven)


I have a maven-managed project with some modules (with jar package). Each module contains its "persistence.xml" file in its META-INF directory.

Another module has the responsibility to package these modules into a war file. But I have not found a way to "combine" these "persistence.xml" files into a single file.

Is it possible?


Solution

  • If you know XSLT, you can write a transform to merge the persistence documents. Maven has a plugin for running XSLT (and validationg XML) - xml-maven-plugin

    But do you need to do this? Reading here, and here, for example, states that persistence.xml will be picked up from all jars, not just the webapp war. So you should be able to leave persistence.xml in your library jars and the will be used by the webapp.