We use MySQL in production, and Derby for unit tests. Our pom.xml copies Derby version of persistence.xml before tests, and replaces it with the MySQL version in prepare-package phase:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>copy-test-persistence</id>
<phase>process-test-resources</phase>
<configuration>
<tasks>
<!--replace the "proper" persistence.xml with the "test" version-->
<copy
file="${project.build.testOutputDirectory}/META-INF/persistence.xml.test"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
overwrite="true" verbose="true" failonerror="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>restore-persistence</id>
<phase>prepare-package</phase>
<configuration>
<tasks>
<!--restore the "proper" persistence.xml-->
<copy
file="${project.build.outputDirectory}/META-INF/persistence.xml.production"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
overwrite="true" verbose="true" failonerror="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is, that if I execute mvn jetty:run it will execute the test persistence.xml file copy task before starting jetty. I want it to be run using the deployment version. How can I fix this?