Java 将一个测试资源移动到Maven中磁盘上的某个位置

Java 将一个测试资源移动到Maven中磁盘上的某个位置,java,unit-testing,maven,maven-resources-plugin,Java,Unit Testing,Maven,Maven Resources Plugin,我有一个位于resources/src/test/dir/sample.json中的测试资源,在运行单元测试之前,它需要移动到/tmp/data/sample.json。我想使用Maven自动移动这个文件,而不干扰需要移动到目标的其他测试资源。原因是在生产环境中,该文件来自jar外部 看看Maven的资源:testResources目标和插件。我不确定在哪里指定outputDirectory,尤其是在不干扰任何其他内容的情况下 随着我的研究,我将发布更多信息,但我特别担心有几种方法可以做到这一点

我有一个位于
resources/src/test/dir/sample.json
中的测试资源,在运行单元测试之前,它需要移动到
/tmp/data/sample.json
。我想使用Maven自动移动这个文件,而不干扰需要移动到目标的其他测试资源。原因是在生产环境中,该文件来自jar外部

看看Maven的
资源:testResources
目标和插件。我不确定在哪里指定
outputDirectory
,尤其是在不干扰任何其他内容的情况下

随着我的研究,我将发布更多信息,但我特别担心有几种方法可以做到这一点,而且不清楚哪种方法是最传统的。

假设您是,您将在
流程测试资源
生命周期中拥有
资源:testResources
。您将需要像往常一样复制测试资源的默认执行和将特定资源复制到特定输出目录的额外执行

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>resources</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>execution1</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>execution2</id>
            <phase>process-test-resources</phase>
            <configuration>
              <outputDirectory>
                 ...
              </outputDirectory>
              <resources>
                 ...
              </resources>
            </configuration>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

...

假设您是,您将在
流程测试资源
生命周期中拥有
资源:testResources
。您将需要像往常一样复制测试资源的默认执行和将特定资源复制到特定输出目录的额外执行

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>resources</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>execution1</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>execution2</id>
            <phase>process-test-resources</phase>
            <configuration>
              <outputDirectory>
                 ...
              </outputDirectory>
              <resources>
                 ...
              </resources>
            </configuration>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

...