我在我的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