如何在pom中获取Maven testResources目录

时间:2015-04-27 15:17:49

标签: maven variables pom.xml elements

在Maven pom.xml中,我可以获得一些在构建部分中定义的构建值。例如${project.build.testSourceDirectory}

    <build>
            <directory>${project.basedir}/target</directory>
            <outputDirectory>${project.build.directory}/classes</outputDirectory>
            <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
            <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
            <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
            <resources>
                <resource>
                    <directory>${project.basedir}/src/main/java/resources</directory>
                </resource>
            </resources>
            <testResources>
                <testResource>
                    <directory>${project.basedir}/src/test/resources</directory>
                </testResource>
            </testResources>
   ...

是否有获取testResources目录的值,testResources目录是testResource下的子元素? 我试过了${project.build.testResources[0].directory},但它不起作用。

2 个答案:

答案 0 :(得分:4)

我一直在寻找相同的价值而最终没有任何结果。这份文件证实了我担心这是不可能的:

http://books.sonatype.com/mvnref-book/reference/resource-filtering-sect-properties.html#resource-filtering-sect-project-properties

答案 1 :(得分:3)

试试这个。

project.testResources[0].directory

它适用于这种环境。

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T18:29:23+01:00) Java version: 1.8.0_45-internal, vendor: Oracle Corporation OS name: "linux", version: "3.13.0-46-generic", arch: "amd64", family: "unix"