我们在生产环境中使用 MySQL,在单元测试中使用 Derby。我们的 pom.xml 在测试之前复制 Derby 版本的 persistence.xml,并在准备包阶段将其替换为 MySQL 版本:
<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>
问题是,如果我执行 mvn jetty:run 它将在启动 jetty 之前执行 test persistence.xml 文件复制任务。我希望它使用部署版本运行。我怎样才能解决这个问题?