运行JUnit配置时,下面的断言失败。
String dirName = System.getProperty("dataDir");
Assert.assertNull(dirName);
参数dataDir在pom.xml中描述
<systemProperties>
<property>
<name>dataDir</name>
<value>src/main/resources/data</value>
</property>
</systemProperties>
答案 0 :(得分:0)
maven-surefire-plugin已弃用系统属性构造 http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html
添加属性的正确方法是
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<buildDirectory>${project.build.directory}</buildDirectory>
</systemPropertyVariables>
答案 1 :(得分:0)
试试这个:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<systemPropertyVariables>
<propertyName>dataDir</propertyName>
<buildDirectory>src/main/resources/data</buildDirectory>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
如果您需要复制库,也可以这样做
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/project/WEB-INF/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>