Maven-在执行测试时将目录添加到类路径 [英] Maven - Add directory to classpath while executing tests

查看:57
本文介绍了Maven-在执行测试时将目录添加到类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中拥有的Junit需要从类路径中加载属性文件.我如何指定这些属性文件的目录,以便Maven在运行测试之前在类路径中进行设置?

The Junits I have in my project need to load property files from the classpath. How can I specify the directory of those property files so that Maven will set that in the classpath before running the tests?

推荐答案

您可以使用

You can use the build-helper-maven-plugin to specify additional test-resource directories as follows. Using the configuration below, the contents of the test-resources directory will be copied to the target/test-classes directory during the generate-test-sources phase:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.12</version>
  <executions>
    <execution>
      <id>add-test-resource</id>
      <phase>generate-test-sources</phase>
      <goals>
        <goal>add-test-resource</goal>
      </goals>
      <configuration>
        <resources>
          <resource>
            <directory>path/to/additional/test/resources</directory>
            <excludes>
              <exclude>**/folder-to-exclude/**</exclude>
            </excludes>
          </resource>
        </resources>
      </configuration>
    </execution> 
  </executions>
</plugin>

这篇关于Maven-在执行测试时将目录添加到类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆