我在我的Maven项目中添加了解决方案this Stack Overflow question。与我介绍的建议解决方案唯一的区别是用<target />
替换<tasks />
(我遇到的问题随任何一个出现)。maven-antrun-plugin跳过执行
在测试方面,一切都非常出色。当我运行我的测试时,正在使用正确的(test-persistence.xml)持久性文件。但是,当我正在执行干净安装或者甚至从我的IDE(Netbeans 8.2)中运行时,只有第一个目标(复制测试持久性)正在执行。第二次执行是在测试之后输入的(请参阅下面的构建输出),但目标未执行。在每个clean install
之后以及在服务器上运行应用程序后,我所得到的结果是test-persistence.xml
的内容位于persistence.xml
文件中。正确的内容保留在第一个目标中创建的persistence.xml.proper
中。
--- maven-antrun-plugin:1.8:run (copy-test-persistence) @ RimmaNew ---
Executing tasks
main:
[copy] Copying 1 file to /my-project-home/target/classes/META-INF
[copy] Copying 1 file to /my-project-home/target/classes/META-INF
Executed tasks
...
--- maven-antrun-plugin:1.8:run (restore-persistence) @ RimmaNew ---
Executing tasks
main:
Executed tasks
您会注意到0任务在restore-persistence
下执行。奇怪的是在创建文件夹/target/antrun
有一个build-main.xml
文件,其中包括跳过的任务:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main" >
<target name="main">
<copy file="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml.proper" tofile="/home/vgorcinschi/NetBeansProjects/rimmanew/target/classes/META-INF/persistence.xml"/>
</target>
</project>
,如果你能给我一个提示,我不能让我的头围绕这一点,将不胜感激。由于这是常见的我张贴我目前的pom.xml
:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-test-persistence</id>
<phase>process-test-resources</phase>
<configuration>
<target>
<!--backup the "proper" persistence.xml-->
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml.proper" />
<!--replace the "proper" persistence.xml with the "test" version-->
<copy file="${project.build.testOutputDirectory}/META-INF/test-persistence.xml" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>restore-persistence</id>
<phase>prepare-package</phase>
<configuration>
<target>
<!--restore the "proper" persistence.xml-->
<copy file="${project.build.outputDirectory}/META-INF/persistence.xml.proper" tofile="${project.build.outputDirectory}/META-INF/persistence.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
辉煌 - 这解决了我的问题。非常感谢你! – vasigorc